Skip to content

Commit b77dcbf

Browse files
committed
Cached query working for UserChartPart
1 parent 1cf9c7d commit b77dcbf

39 files changed

+1011
-523
lines changed

Signum.Engine.Extensions/Dashboard/DashboardLogic.cs

Lines changed: 276 additions & 38 deletions
Large diffs are not rendered by default.

Signum.Engine.Extensions/MachineLearning/PredictorLogic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static void RegisterPublication(PredictorPublicationSymbol publication, P
7474
return Trainings.TryGetC(lite)?.Context;
7575
}
7676

77-
public static void Start(SchemaBuilder sb, Func<IFileTypeAlgorithm> predictorFileAlgorithm)
77+
public static void Start(SchemaBuilder sb, IFileTypeAlgorithm predictorFileAlgorithm)
7878
{
7979
if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
8080
{
@@ -143,7 +143,7 @@ public static void Start(SchemaBuilder sb, Func<IFileTypeAlgorithm> predictorFil
143143
e.AccuracyValidation,
144144
});
145145

146-
FileTypeLogic.Register(PredictorFileType.PredictorFile, predictorFileAlgorithm());
146+
FileTypeLogic.Register(PredictorFileType.PredictorFile, predictorFileAlgorithm);
147147

148148
SymbolLogic<PredictorAlgorithmSymbol>.Start(sb, () => Algorithms.Keys);
149149
SymbolLogic<PredictorColumnEncodingSymbol>.Start(sb, () => Algorithms.Values.SelectMany(a => a.GetRegisteredEncodingSymbols()).Distinct());

Signum.Engine.MachineLearning.TensorFlow/Signum.Engine.MachineLearning.TensorFlow.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414
<ItemGroup>
1515
<PackageReference Include="Signum.Analyzer" Version="3.2.0" />
16-
<PackageReference Include="Signum.MSBuildTask" Version="5.0.0" />
16+
<PackageReference Include="Signum.MSBuildTask" Version="6.0.0" />
1717
<PackageReference Include="TensorFlow.Keras" Version="0.6.4" />
1818
</ItemGroup>
1919

Signum.Engine/Engine/SchemaSynchronizer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ public static string GetDefaultValue(ITable table, IColumn column, Replacements
625625
column.DbType.IsString() ? "''" :
626626
column.DbType.IsDate() ? "GetDate()" :
627627
column.DbType.IsGuid() ? "NEWID()" :
628+
column.DbType.IsTime() ? "'00:00'" :
628629
"?");
629630

630631
string defaultValue = rep.Interactive ? SafeConsole.AskString($"Default value for '{table.Name.Name}.{column.Name}'? ([Enter] for {typeDefault} or 'force' if there are no {(forNewColumn ? "rows" : "nulls")}) ", stringValidator: str => null) : "";
Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,76 @@
1-
using System.Collections.Immutable;
2-
using System.Text.Json;
3-
using System.Text.Json.Serialization;
4-
5-
namespace Signum.Engine.Json;
6-
7-
public static class EntityJsonContext
8-
{
9-
public static JsonSerializerOptions FullJsonSerializerOptions;
10-
static EntityJsonContext()
11-
{
12-
var ejcf = new EntityJsonConverterFactory();
13-
14-
FullJsonSerializerOptions = new JsonSerializerOptions
15-
{
16-
IncludeFields = true,
17-
Converters =
18-
{
19-
ejcf,
20-
new MListJsonConverterFactory(ejcf.AssertCanWrite),
21-
new LiteJsonConverterFactory(),
22-
new JsonStringEnumConverter(),
23-
new TimeSpanConverter(),
24-
new DateOnlyConverter()
25-
}
26-
};
27-
}
28-
29-
static readonly ThreadVariable<ImmutableStack<(PropertyRoute pr, ModifiableEntity? mod, PrimaryKey? rowId)>?> currentPropertyRoute = Statics.ThreadVariable<ImmutableStack<(PropertyRoute pr, ModifiableEntity? mod, PrimaryKey ? rowId) >?>("jsonPropertyRoute");
30-
31-
public static (PropertyRoute pr, ModifiableEntity? mod, PrimaryKey? rowId)? CurrentPropertyRouteAndEntity
32-
{
33-
get { return currentPropertyRoute.Value?.Peek(); }
34-
}
35-
36-
public static IRootEntity? FindCurrentRootEntity()
37-
{
38-
return currentPropertyRoute.Value?.FirstOrDefault(a => a.mod is IRootEntity).mod as IRootEntity;
39-
}
40-
41-
public static PrimaryKey? FindCurrentRowId()
42-
{
43-
return currentPropertyRoute.Value?.Where(a => a.rowId != null).FirstOrDefault().rowId;
44-
}
45-
46-
public static IDisposable SetCurrentPropertyRouteAndEntity((PropertyRoute, ModifiableEntity?, PrimaryKey? rowId) pair)
47-
{
48-
var old = currentPropertyRoute.Value;
49-
50-
currentPropertyRoute.Value = (old ?? ImmutableStack<(PropertyRoute pr, ModifiableEntity? mod, PrimaryKey? rowId)>.Empty).Push(pair);
51-
52-
return new Disposable(() => { currentPropertyRoute.Value = old; });
53-
}
54-
55-
static readonly ThreadVariable<bool> allowDirectMListChangesVariable = Statics.ThreadVariable<bool>("allowDirectMListChanges");
56-
57-
public static bool AllowDirectMListChanges
58-
{
59-
get { return allowDirectMListChangesVariable.Value; }
60-
}
61-
62-
public static IDisposable SetAllowDirectMListChanges(bool allowMListDirectChanges)
63-
{
64-
var old = allowDirectMListChangesVariable.Value;
65-
66-
allowDirectMListChangesVariable.Value = allowMListDirectChanges;
67-
68-
return new Disposable(() => { allowDirectMListChangesVariable.Value = old; });
69-
}
70-
71-
72-
73-
}
1+
using System.Collections.Immutable;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace Signum.Engine.Json;
6+
7+
public static class EntityJsonContext
8+
{
9+
public static JsonSerializerOptions FullJsonSerializerOptions;
10+
static EntityJsonContext()
11+
{
12+
var ejcf = new EntityJsonConverterFactory();
13+
14+
FullJsonSerializerOptions = new JsonSerializerOptions
15+
{
16+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
17+
IncludeFields = true,
18+
Converters =
19+
{
20+
ejcf,
21+
new LiteJsonConverterFactory(),
22+
new MListJsonConverterFactory(ejcf.AssertCanWrite),
23+
new JsonStringEnumConverter(),
24+
new ResultTableConverter(),
25+
new TimeSpanConverter(),
26+
new DateOnlyConverter(),
27+
new TimeOnlyConverter()
28+
}
29+
};
30+
}
31+
32+
static readonly ThreadVariable<ImmutableStack<(PropertyRoute pr, ModifiableEntity? mod, PrimaryKey? rowId)>?> currentPropertyRoute = Statics.ThreadVariable<ImmutableStack<(PropertyRoute pr, ModifiableEntity? mod, PrimaryKey ? rowId) >?>("jsonPropertyRoute");
33+
34+
public static (PropertyRoute pr, ModifiableEntity? mod, PrimaryKey? rowId)? CurrentPropertyRouteAndEntity
35+
{
36+
get { return currentPropertyRoute.Value?.Peek(); }
37+
}
38+
39+
public static IRootEntity? FindCurrentRootEntity()
40+
{
41+
return currentPropertyRoute.Value?.FirstOrDefault(a => a.mod is IRootEntity).mod as IRootEntity;
42+
}
43+
44+
public static PrimaryKey? FindCurrentRowId()
45+
{
46+
return currentPropertyRoute.Value?.Where(a => a.rowId != null).FirstOrDefault().rowId;
47+
}
48+
49+
public static IDisposable SetCurrentPropertyRouteAndEntity((PropertyRoute, ModifiableEntity?, PrimaryKey? rowId) pair)
50+
{
51+
var old = currentPropertyRoute.Value;
52+
53+
currentPropertyRoute.Value = (old ?? ImmutableStack<(PropertyRoute pr, ModifiableEntity? mod, PrimaryKey? rowId)>.Empty).Push(pair);
54+
55+
return new Disposable(() => { currentPropertyRoute.Value = old; });
56+
}
57+
58+
static readonly ThreadVariable<bool> allowDirectMListChangesVariable = Statics.ThreadVariable<bool>("allowDirectMListChanges");
59+
60+
public static bool AllowDirectMListChanges
61+
{
62+
get { return allowDirectMListChangesVariable.Value; }
63+
}
64+
65+
public static IDisposable SetAllowDirectMListChanges(bool allowMListDirectChanges)
66+
{
67+
var old = allowDirectMListChangesVariable.Value;
68+
69+
allowDirectMListChangesVariable.Value = allowMListDirectChanges;
70+
71+
return new Disposable(() => { allowDirectMListChangesVariable.Value = old; });
72+
}
73+
74+
75+
76+
}

Signum.Engine/Json/FilterJsonConverter.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ public override bool CanConvert(Type objectType)
1515

1616
public override void Write(Utf8JsonWriter writer, FilterTS value, JsonSerializerOptions options)
1717
{
18-
throw new NotImplementedException();
18+
if (value is FilterConditionTS fc)
19+
JsonSerializer.Serialize(writer, fc, options);
20+
else if (value is FilterGroupTS fg)
21+
JsonSerializer.Serialize(writer, fg, options);
22+
else
23+
throw new UnexpectedValueException(value);
1924
}
2025

2126
public override FilterTS? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
@@ -121,7 +126,7 @@ public override Filter ToFilter(QueryDescription qd, bool canAggregate, JsonSeri
121126
public class ColumnTS
122127
{
123128
public string token;
124-
public string displayName;
129+
public string? displayName;
125130

126131
public Column ToColumn(QueryDescription qd, bool canAggregate)
127132
{
@@ -280,7 +285,22 @@ public class QueryRequestTS
280285
public List<OrderTS> orders;
281286
public List<ColumnTS> columns;
282287
public PaginationTS pagination;
283-
public SystemTimeTS/*?*/ systemTime;
288+
public SystemTimeTS? systemTime;
289+
290+
public static QueryRequestTS FromQueryRequest(QueryRequest qr)
291+
{
292+
return new QueryRequestTS
293+
{
294+
queryKey = QueryUtils.GetKey(qr.QueryName),
295+
queryUrl = qr.QueryUrl,
296+
groupResults = qr.GroupResults,
297+
columns = qr.Columns.Select(c => new ColumnTS { token = c.Token.FullKey(), displayName = c.DisplayName }).ToList(),
298+
filters = qr.Filters.Select(f => FilterTS.FromFilter(f)).ToList(),
299+
orders = qr.Orders.Select(o => new OrderTS { orderType = o.OrderType, token = o.Token.FullKey() }).ToList(),
300+
pagination = new PaginationTS(qr.Pagination),
301+
systemTime = qr.SystemTime == null ? null : new SystemTimeTS(qr.SystemTime),
302+
};
303+
}
284304

285305
public QueryRequest ToQueryRequest(JsonSerializerOptions jsonSerializerOptions)
286306
{

Signum.Entities.Extensions/Dashboard/CachedQuery.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@
55

66
namespace Signum.Entities.Dashboard;
77

8-
[EntityKind(EntityKind.System, EntityData.Master), TicksColumn(false)]
8+
[EntityKind(EntityKind.System, EntityData.Master)]
99
public class CachedQueryEntity : Entity
1010
{
1111
public Lite<DashboardEntity> Dashboard { get; set; }
1212

13+
[PreserveOrder, NoRepeatValidator]
1314
[ImplementedBy(typeof(UserQueryEntity), typeof(UserChartEntity))]
14-
public Lite<IUserAssetEntity> UserAsset { get; set; }
15+
public MList<Lite<IUserAssetEntity>> UserAssets { get; set; } = new MList<Lite<IUserAssetEntity>>();
1516

1617
[DefaultFileType(nameof(CachedQueryFileType.CachedQuery), nameof(CachedQueryFileType))]
1718
public FilePathEmbedded File { get; set; }
19+
20+
public int NumRows { get; set; }
21+
22+
public int NumColumns { get; set; }
23+
24+
public DateTime CreationDate { get; internal set; }
25+
26+
[Unit("ms")]
27+
public long QueryDuration { get; set; }
28+
29+
[Unit("ms")]
30+
public long UploadDuration { get; set; }
1831
}
1932

2033
[AutoInit]

Signum.Entities.Extensions/Dashboard/DashboardEntity.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Lite<TypeEntity>? EntityType
4343

4444
public bool CombineSimilarRows { get; set; } = true;
4545

46-
public CachedQueriesEmbedded? CachedQueries { get; set; }
46+
public CacheQueryConfigurationEmbedded? CacheQueryConfiguration { get; set; }
4747

4848
[NotifyCollectionChanged, NotifyChildProperty]
4949
[NoRepeatValidator]
@@ -123,13 +123,15 @@ public DashboardEntity Clone()
123123
{
124124
return new DashboardEntity
125125
{
126-
DisplayName = "Clone {0}".FormatWith(this.DisplayName),
127-
DashboardPriority = DashboardPriority,
128-
Parts = Parts.Select(p => p.Clone()).ToMList(),
129-
Owner = Owner,
130126
EntityType = this.EntityType,
131127
EmbeddedInEntity = this.EmbeddedInEntity,
128+
Owner = Owner,
129+
DashboardPriority = DashboardPriority,
132130
AutoRefreshPeriod = this.AutoRefreshPeriod,
131+
DisplayName = "Clone {0}".FormatWith(this.DisplayName),
132+
CombineSimilarRows = this.CombineSimilarRows,
133+
CacheQueryConfiguration = this.CacheQueryConfiguration?.Clone(),
134+
Parts = Parts.Select(p => p.Clone()).ToMList(),
133135
Key = this.Key
134136
};
135137
}
@@ -144,6 +146,7 @@ public XElement ToXml(IToXmlContext ctx)
144146
DashboardPriority == null ? null! : new XAttribute("DashboardPriority", DashboardPriority.Value.ToString()),
145147
EmbeddedInEntity == null ? null! : new XAttribute("EmbeddedInEntity", EmbeddedInEntity.Value.ToString()),
146148
new XAttribute("CombineSimilarRows", CombineSimilarRows),
149+
CacheQueryConfiguration?.ToXml(ctx),
147150
new XElement("Parts", Parts.Select(p => p.ToXml(ctx))));
148151
}
149152

@@ -156,6 +159,7 @@ public void FromXml(XElement element, IFromXmlContext ctx)
156159
DashboardPriority = element.Attribute("DashboardPriority")?.Let(a => int.Parse(a.Value));
157160
EmbeddedInEntity = element.Attribute("EmbeddedInEntity")?.Let(a => a.Value.ToEnum<DashboardEmbedededInEntity>());
158161
CombineSimilarRows = element.Attribute("CombineSimilarRows")?.Let(a => bool.Parse(a.Value)) ?? false;
162+
CacheQueryConfiguration = CacheQueryConfiguration.CreateOrAssignEmbedded(element.Element(nameof(CacheQueryConfiguration)), (cqc, elem) => cqc.FromXml(elem));
159163
Parts.Synchronize(element.Element("Parts")!.Elements().ToList(), (pp, x) => pp.FromXml(x, ctx));
160164
}
161165

@@ -170,7 +174,7 @@ public void FromXml(XElement element, IFromXmlContext ctx)
170174
return ValidationMessage._0IsNotAllowed.NiceToString(pi.NiceName());
171175
}
172176

173-
if(pi.Name == nameof(CachedQueries) && CachedQueries != null && EntityType != null)
177+
if(pi.Name == nameof(CacheQueryConfiguration) && CacheQueryConfiguration != null && EntityType != null)
174178
{
175179
return ValidationMessage._0ShouldBeNullWhen1IsSet.NiceToString(pi.NiceName(), NicePropertyName(() => EntityType));
176180
}
@@ -179,10 +183,29 @@ public void FromXml(XElement element, IFromXmlContext ctx)
179183
}
180184
}
181185

182-
public class CachedQueriesEmbedded : EmbeddedEntity
186+
public class CacheQueryConfigurationEmbedded : EmbeddedEntity
183187
{
184188
[Unit("s")]
185189
public int TimeoutForQueries { get; set; } = 5 * 60;
190+
191+
public int MaxRows { get; set; } = 1000 * 1000;
192+
193+
internal CacheQueryConfigurationEmbedded Clone() => new CacheQueryConfigurationEmbedded
194+
{
195+
TimeoutForQueries = TimeoutForQueries,
196+
MaxRows = MaxRows,
197+
};
198+
199+
internal XElement ToXml(IToXmlContext ctx) => new XElement("CacheQueryConfiguration",
200+
new XAttribute(nameof(TimeoutForQueries), TimeoutForQueries),
201+
new XAttribute(nameof(MaxRows), MaxRows)
202+
);
203+
204+
internal void FromXml(XElement elem)
205+
{
206+
TimeoutForQueries = elem.Attribute(nameof(TimeoutForQueries))?.Value.ToInt() ?? 5 * 60;
207+
MaxRows = elem.Attribute(nameof(MaxRows))?.Value.ToInt() ?? 1000 * 1000;
208+
}
186209
}
187210

188211
[AutoInit]

0 commit comments

Comments
 (0)