-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLPDataManager.cs
More file actions
110 lines (102 loc) · 4.31 KB
/
Copy pathLPDataManager.cs
File metadata and controls
110 lines (102 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
using LumenWorks.Framework.IO.Csv;
using Caculation.Module.Provider;
using Caculation.Module.Interface;
using Common.Module.Interface;
using Common.Module.Models;
namespace Data.Module.Provider
{
public class LPDataManager<T> : DataManagerBase<T>, IDataManager<T>, IFileReaderDataManager<T> where T : LPDatModel
{
const string DataValue = "Data Value";
public LPDataManager()
{
this.calculationManager = new CalculationManager();
}
public IList<T> GenerateData(CsvReader csv)
{
List<T> fieldValue = new List<T>();
LPDatModel dataModel;
string[] headers = csv.GetFieldHeaders();
int fieldCount = csv.FieldCount;
while (csv.ReadNextRecord())
{
dataModel = new LPDatModel();
for (int i = 0; i < fieldCount; i++)
{
switch (headers[i])
{
case MeterPointCode:
dataModel.MeterPointCode = csv[i];
break;
case SerialNumber:
dataModel.SerialNumber = csv[i];
break;
case PlantCode:
dataModel.PlantCode = csv[i];
break;
case Date:
DateTime dt = new DateTime();
if (DateTime.TryParse(csv[i], out dt))
{
dataModel.Date = dt;
}
break;
case DataType:
dataModel.DataType = csv[i];
break;
case DataValue:
double tempValue = 0;
if (double.TryParse(csv[i], out tempValue))
{
dataModel.DataValue = tempValue;
}
else
{
dataModel.IsValidData = false;
dataModel.InvalidDataList.Add(DataValue, csv[i]);
}
break;
case Status:
dataModel.Status = csv[i];
break;
}
}
fieldValue.Add((T)dataModel);
}
return fieldValue;
}
public double GetMedianValue(IList<T> dataList)
{
var resultList = dataList.Where(d => d.IsValidData == true).Select(m => m.DataValue).ToList();
if (resultList.Count == 0)
throw new ArgumentNullException();
return this.calculationManager.CaculateMedianValue(resultList);
}
public IList<T> FindAboveGivenValue(IList<T> dataList, double minValue, int compareValue)
{
double percentageVal = this.calculationManager.FindPercentageValue(minValue, compareValue);
var resultList = dataList.Where(d => d.IsValidData == true && d.DataValue > percentageVal).ToList();
return resultList;
}
public IList<T> FindBelowGivenValue(IList<T> dataList, double minValue, int compareValue)
{
double percentageVal = this.calculationManager.FindPercentageValue(minValue, compareValue);
var resultList = dataList.Where(d => d.IsValidData == true && d.DataValue < percentageVal).ToList();
return resultList;
}
public IList<T> FindAboveAndBelowGivenValue(IList<T> dataList, double minValue, int compareValue)
{
double percentageVal = this.calculationManager.FindPercentageValue(minValue, compareValue);
var resultList = dataList.Where(d => d.IsValidData== true && (d.DataValue < percentageVal || d.DataValue > percentageVal)).ToList();
return resultList;
}
public IList<T> FindInvalidData(IList<T> dataList)
{
var resultList = dataList.Where(d => d.IsValidData == false).ToList();
return resultList;
}
}
}