Skip to content

Commit 03729d8

Browse files
author
Billy Ernest
committed
Updated the way time windows are processed.
1 parent a806129 commit 03729d8

File tree

2 files changed

+36
-86
lines changed

2 files changed

+36
-86
lines changed

Source/Applications/openECA/openECAClient/DataHub.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private TypeMapping ParseTimeWindow(TypeMapping typeMapping)
259259
else
260260
{
261261
am.WindowUnit = GetTimeSpan(parts[index]);
262-
++index;
262+
index += 2;
263263
if (parts.Length - 1 > index)
264264
{
265265
am.SampleRate = Convert.ToDecimal(parts[index]);
@@ -284,7 +284,7 @@ private TypeMapping ParseTimeWindow(TypeMapping typeMapping)
284284
am.SampleUnit = typeMapping.FieldMappings[i].SampleUnit;
285285
am.TimeWindowExpression = "";
286286

287-
am.RelativeTime = Convert.ToDecimal(parts[index]);
287+
am.RelativeTime = Convert.ToDecimal(parts[++index]);
288288
++index;
289289

290290
if (parts[index].Equals("points", StringComparison.OrdinalIgnoreCase))
@@ -303,7 +303,7 @@ private TypeMapping ParseTimeWindow(TypeMapping typeMapping)
303303

304304
if(parts.Length > ++index)
305305
{
306-
am.SampleRate = Convert.ToDecimal(parts[index]);
306+
am.SampleRate = Convert.ToDecimal(parts[++index]);
307307
index += 2;
308308
am.SampleUnit = GetTimeSpan(parts[index]);
309309
}
@@ -321,7 +321,7 @@ private TypeMapping ParseTimeWindow(TypeMapping typeMapping)
321321

322322
if (parts[index].Equals("points", StringComparison.OrdinalIgnoreCase))
323323
{
324-
index +=2;
324+
index +=3;
325325
typeMapping.FieldMappings[i].RelativeUnit = TimeSpan.Zero;
326326
if(parts.Length > index)
327327
{

Source/Applications/openECA/openECAClient/wwwroot/UserDefinedMappings.cshtml

Lines changed: 32 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@
215215
$('#filelocation').append(directory);
216216
});
217217
218-
//GetData();
219218
});
220219
221220
// Client function called from the dataHub when meta data gets recieved
@@ -350,14 +349,42 @@
350349
$('#recordCount').text(data.length);
351350
352351
});
352+
dataHub.getMappingCompilerErrors().done(function (data) {
353+
errorList = data;
354+
355+
if (errorList.length == 0) {
356+
if ($('#error-count').length)
357+
hideErrorMessage();
358+
359+
$('#modal-errors').modal('hide');
360+
} else if (errorList.length > 0) {
361+
var anchor = $('<a href="#" id="error-count">');
362+
363+
if (data.length == 1)
364+
anchor.append('1 error');
365+
else
366+
anchor.append(data.length + ' errors');
367+
368+
UpdateErrorModal();
369+
showErrorMessage(anchor.prop('outerHTML') + ' occurred during mapping compilation.');
370+
371+
$('#error-count').click(function (e) {
372+
$('#modal-errors').modal('show');
373+
return false;
374+
});
375+
}
376+
}).fail(function (error) {
377+
showErrorMessage(error);
378+
});
379+
353380
});
354381
355382
}
356383
357384
$scope.getExpressions = function (item) {
358385
var fieldString = "";
359386
$.each(item.FieldMappings, function (i, fieldMapping) {
360-
fieldString += fieldMapping.Field.Identifier + ' to ' + fieldMapping.Expression;
387+
fieldString += fieldMapping.Field.Identifier + ' to ' + fieldMapping.Expression + (fieldMapping.TimeWindowExpression != null? ' ' + fieldMapping.TimeWindowExpression: '');
361388
if (i < item.FieldMappings.length - 1)
362389
fieldString += ', ';
363390
});
@@ -491,83 +518,6 @@
491518
492519
493520
});
494-
495-
function GetData() {
496-
udts = [];
497-
mappings = [];
498-
499-
$('#identifier').val("");
500-
$('#types').empty();
501-
$('#userdefinedmappings tbody').empty();
502-
503-
dataHub.getDefinedTypes().done(function (data) {
504-
$.each(data, function (i, dataType) {
505-
if (dataType.IsUserDefined) {
506-
$('#types').append($('<option />').val(dataType.Category + '~' + dataType.Identifier + '~' + dataType.IsArray + '~' + dataType.IsUserDefined + '~' + i).text(dataType.Category + ' ' + dataType.Identifier));
507-
udts.push(dataType);
508-
}
509-
});
510-
511-
UpdateTypeMappings();
512-
513-
dataHub.getDefinedMappings().done(function (data) {
514-
$.each(data, function (i, typeMapping) {
515-
var fieldsString = '';
516-
517-
mappings.push(typeMapping);
518-
519-
$.each(typeMapping.FieldMappings, function (i, fieldMapping) {
520-
fieldsString += fieldMapping.Field.Identifier + ' to ' + fieldMapping.Expression;
521-
if (i < typeMapping.FieldMappings.length - 1)
522-
fieldsString += ', ';
523-
});
524-
525-
$('#userdefinedmappings tbody').append($('<tr><td>' + typeMapping.Type.Category + ' ' + typeMapping.Type.Identifier + '</td><td>' + typeMapping.Identifier + '</td><td>' + fieldsString + '</td><td><button id="updatebtn' + i + '"class="btn btn-link" hub-dependent><span class="glyphicon glyphicon-pencil"></span></button><button id="btn' + i + '" class="btn btn-link" hub-dependent><span class="glyphicon glyphicon-remove-sign"></span></button></td></tr>'));
526-
527-
$('#btn' + i).one('click', function (e) {
528-
RemoveMapping(typeMapping);
529-
});
530-
531-
$('#updatebtn' + i).on('click', function (e) {
532-
UpdateMapping(typeMapping);
533-
});
534-
});
535-
536-
}).fail(function (error) {
537-
showErrorMessage(error);
538-
});
539-
}).fail(function (error) {
540-
showErrorMessage(error);
541-
});
542-
543-
dataHub.getMappingCompilerErrors().done(function (data) {
544-
errorList = data;
545-
546-
if (errorList.length == 0) {
547-
if ($('#error-count').length)
548-
hideErrorMessage();
549-
550-
$('#modal-errors').modal('hide');
551-
} else if (errorList.length > 0) {
552-
var anchor = $('<a href="#" id="error-count">');
553-
554-
if (data.length == 1)
555-
anchor.append('1 error');
556-
else
557-
anchor.append(data.length + ' errors');
558-
559-
UpdateErrorModal();
560-
showErrorMessage(anchor.prop('outerHTML') + ' occurred during mapping compilation.');
561-
562-
$('#error-count').click(function (e) {
563-
$('#modal-errors').modal('show');
564-
return false;
565-
});
566-
}
567-
}).fail(function (error) {
568-
showErrorMessage(error);
569-
});
570-
}
571521
572522
function UpdateTypeMappings() {
573523
$('#modals').children().remove();
@@ -740,15 +690,15 @@
740690
741691
}
742692
else if ($(d).is('select')) {
743-
$(d).val(data.FieldMappings[i].Expression.split(' ')[0]);
693+
$(d).val(data.FieldMappings[i].Expression);
744694
}
745695
else if ($(d).is('input')) {
746-
$(d).val(data.FieldMappings[i].Expression.split(' ')[0]);
696+
$(d).val(data.FieldMappings[i].Expression);
747697
}
748698
});
749699
750700
$.each($('#fields li div').children('[id*="timeWindow"]'), function (i, d) {
751-
$(d).val(data.FieldMappings[i].Expression.split(' ')[1]);
701+
$(d).val(data.FieldMappings[i].TimeWindowExpression);
752702
});
753703
754704
$('#addnewmapping').attr('disabled', false);

0 commit comments

Comments
 (0)