• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.0)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Rdmp.Core/DataViewing/ViewColumnExtractCollection.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using System.Linq;
10
using FAnsi;
11
using FAnsi.Discovery.QuerySyntax;
12
using Rdmp.Core.Curation.Data;
13
using Rdmp.Core.Curation.Data.Dashboarding;
14
using Rdmp.Core.Curation.Data.Spontaneous;
15
using Rdmp.Core.MapsDirectlyToDatabaseTable;
16
using Rdmp.Core.QueryBuilding;
17
using Rdmp.Core.Repositories;
18
using Rdmp.Core.ReusableLibraryCode.DataAccess;
19

20
namespace Rdmp.Core.DataViewing;
21

22
/// <summary>
23
/// Builds a query to fetch data in a <see cref="ColumnInfo"/> (Based on the <see cref="ViewType"/>)
24
/// </summary>
25
public class ViewColumnExtractCollection : PersistableObjectCollection, IViewSQLAndResultsCollection
26
{
27
    public ViewType ViewType { get; private set; }
×
28

29
    /// <summary>
30
    /// The SELECT column (can be null if this instance was constructed using a <see cref="ColumnInfo"/>)
31
    /// </summary>
32
    public ExtractionInformation ExtractionInformation =>
33
        DatabaseObjects.OfType<ExtractionInformation>().SingleOrDefault();
×
34

35
    /// <summary>
36
    /// The SELECT column (can be null if this instance was constructed using a <see cref="ExtractionInformation"/>)
37
    /// </summary>
38
    public ColumnInfo ColumnInfo => DatabaseObjects.OfType<ColumnInfo>().SingleOrDefault();
×
39

40

41
    #region Constructors
42

43
    /// <summary>
44
    /// for persistence, do not use
45
    /// </summary>
46
    public ViewColumnExtractCollection()
×
47
    {
48
    }
×
49

50
    public ViewColumnExtractCollection(ColumnInfo c, ViewType viewType, IFilter filter = null) : this()
×
51
    {
52
        DatabaseObjects.Add(c);
×
53
        if (filter != null)
×
54
            DatabaseObjects.Add(filter);
×
55
        ViewType = viewType;
×
56
    }
×
57

58
    public ViewColumnExtractCollection(ColumnInfo c, ViewType viewType, IContainer container) : this()
×
59
    {
60
        DatabaseObjects.Add(c);
×
61
        if (container != null)
×
62
            DatabaseObjects.Add(container);
×
63
        ViewType = viewType;
×
64
    }
×
65

66
    public ViewColumnExtractCollection(ExtractionInformation ei, ViewType viewType, IFilter filter = null) : this()
×
67
    {
68
        DatabaseObjects.Add(ei);
×
69
        if (filter != null)
×
70
            DatabaseObjects.Add(filter);
×
71
        ViewType = viewType;
×
72
    }
×
73

74
    public ViewColumnExtractCollection(ExtractionInformation ei, ViewType viewType, IContainer container) : this()
×
75
    {
76
        DatabaseObjects.Add(ei);
×
77
        if (container != null)
×
78
            DatabaseObjects.Add(container);
×
79
        ViewType = viewType;
×
80
    }
×
81

82
    #endregion
83

84
    public override string SaveExtraText() => PersistStringHelper.SaveDictionaryToString(new Dictionary<string, string>
×
85
        { { "ViewType", ViewType.ToString() } });
×
86

87
    public override void LoadExtraText(string s)
88
    {
89
        var value = PersistStringHelper.GetValueIfExistsFromPersistString("ViewType", s);
×
90
        ViewType = (ViewType)Enum.Parse(typeof(ViewType), value);
×
91
    }
×
92

93
    public IEnumerable<DatabaseEntity> GetToolStripObjects()
94
    {
95
        if (GetFilterIfAny() is ConcreteFilter f)
×
96
            yield return f;
×
97

98
        if (GetContainerIfAny() is ConcreteContainer c)
×
99
            yield return c;
×
100

101
        yield return GetTableInfo() as TableInfo;
×
102
    }
×
103

104
    public IDataAccessPoint GetDataAccessPoint() => GetTableInfo();
×
105

106
    private ITableInfo GetTableInfo() => ExtractionInformation != null
×
107
        ? ExtractionInformation.ColumnInfo?.TableInfo
×
108
        : (ITableInfo)ColumnInfo?.TableInfo;
×
109

110
    public string GetSql()
111
    {
112
        var qb = new QueryBuilder(null, null, new[] { GetTableInfo() });
×
113

114
        if (ViewType == ViewType.TOP_100)
×
115
            qb.TopX = 100;
×
116

117
        if (ViewType == ViewType.Distribution)
×
118
            AddDistributionColumns(qb);
×
119
        else
120
            qb.AddColumn(GetIColumn());
×
121

122
        var filter = GetFilterIfAny();
×
123
        var container = GetContainerIfAny();
×
124

125
        if (filter != null && container != null)
×
126
            throw new Exception("Cannot generate SQL with both filter and container");
×
127

128
        if (filter != null && !string.IsNullOrWhiteSpace(filter.WhereSQL))
×
129
            qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null,
×
130
                new[] { filter }, FilterContainerOperation.AND);
×
131
        else if (container != null) qb.RootFilterContainer = container;
×
132

133
        if (ViewType == ViewType.Aggregate)
×
134
            qb.AddCustomLine("count(*) as Count,", QueryComponent.QueryTimeColumn);
×
135

136
        var sql = qb.SQL;
×
137

138
        if (ViewType == ViewType.Aggregate)
×
139
            sql += $"{Environment.NewLine} GROUP BY {GetColumnSelectSql()}";
×
140

141
        if (ViewType == ViewType.Aggregate)
×
142
            sql += $"{Environment.NewLine} ORDER BY count(*) DESC";
×
143

144
        return sql;
×
145
    }
146

147
    private IColumn GetIColumn()
148
    {
149
        if (ExtractionInformation != null) return ExtractionInformation;
×
150
        return ColumnInfo != null ? new ColumnInfoToIColumn(new MemoryRepository(), ColumnInfo) : (IColumn)null;
×
151
    }
152

153
    private void AddDistributionColumns(QueryBuilder qb)
154
    {
155
        var repo = new MemoryRepository();
×
156
        qb.AddColumn(new SpontaneouslyInventedColumn(repo, "CountTotal", "count(1)"));
×
157
        qb.AddColumn(new SpontaneouslyInventedColumn(repo, "CountNull",
×
158
            $"SUM(CASE WHEN {GetColumnSelectSql()} IS NULL THEN 1 ELSE 0  END)"));
×
159
        qb.AddColumn(new SpontaneouslyInventedColumn(repo, "CountZero",
×
160
            $"SUM(CASE WHEN {GetColumnSelectSql()} = 0 THEN 1  ELSE 0 END)"));
×
161

162
        qb.AddColumn(new SpontaneouslyInventedColumn(repo, "Max", $"max({GetColumnSelectSql()})"));
×
163
        qb.AddColumn(new SpontaneouslyInventedColumn(repo, "Min", $"min({GetColumnSelectSql()})"));
×
164

165
        switch (ColumnInfo.GetQuerySyntaxHelper().DatabaseType)
×
166
        {
167
            case DatabaseType.MicrosoftSQLServer:
168
                qb.AddColumn(new SpontaneouslyInventedColumn(repo, "stdev ", $"stdev({GetColumnSelectSql()})"));
×
169
                break;
×
170
            case DatabaseType.MySql:
171
            case DatabaseType.Oracle:
172
                qb.AddColumn(new SpontaneouslyInventedColumn(repo, "stddev ", $"stddev({GetColumnSelectSql()})"));
×
173
                break;
×
174
            default:
175
                throw new ArgumentOutOfRangeException();
×
176
        }
177

178
        qb.AddColumn(new SpontaneouslyInventedColumn(repo, "avg", $"avg({GetColumnSelectSql()})"));
×
179
    }
×
180

181
    /// <summary>
182
    /// Returns the column Select SQL (without alias) for use in query building
183
    /// </summary>
184
    /// <returns></returns>
185
    private string GetColumnSelectSql() => GetIColumn().SelectSQL;
×
186

187
    public string GetTabName() => $"{GetIColumn()}({ViewType})";
×
188

189
    public void AdjustAutocomplete(IAutoCompleteProvider autoComplete)
190
    {
191
        if (ColumnInfo != null) autoComplete.Add(ColumnInfo);
×
192
    }
×
193

194
    private IFilter GetFilterIfAny()
195
    {
196
        return (IFilter)DatabaseObjects.SingleOrDefault(o => o is IFilter);
×
197
    }
198

199
    private IContainer GetContainerIfAny()
200
    {
201
        return (IContainer)DatabaseObjects.SingleOrDefault(o => o is IContainer);
×
202
    }
203

204

205
    public IQuerySyntaxHelper GetQuerySyntaxHelper()
206
    {
207
        var c = ColumnInfo;
×
208
        return c?.GetQuerySyntaxHelper();
×
209
    }
210
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc