1 |
ebe96ca4
|
Roman Kalivoda
|
//
|
2 |
|
|
// Author: Roman Kalivoda
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
using System.Collections.Generic;
|
6 |
|
|
using System;
|
7 |
|
|
using ServerApp.Parser.Parsers;
|
8 |
|
|
|
9 |
|
|
namespace ServerApp.Predictor
|
10 |
|
|
{
|
11 |
|
|
/// <summary>
|
12 |
|
|
/// A class responsible for preparation of features for classifiers.
|
13 |
|
|
/// </summary>
|
14 |
|
|
public class FeatureExtractor
|
15 |
|
|
{
|
16 |
|
|
/// <summary>
|
17 |
|
|
/// A DataParser instance used to access info objects.
|
18 |
|
|
/// </summary>
|
19 |
|
|
private readonly IDataParser dataParser;
|
20 |
|
|
|
21 |
|
|
private Dictionary<string, int> buildingsToAreas;
|
22 |
|
|
|
23 |
|
|
/// <summary>
|
24 |
|
|
/// Instantiates new FeatureExtractor class.
|
25 |
|
|
/// </summary>
|
26 |
|
|
/// <param name="dataParser">Data parser used to access training data.</param>
|
27 |
|
|
public FeatureExtractor(IDataParser dataParser, Dictionary<string, int> buildingsToAreas)
|
28 |
|
|
{
|
29 |
|
|
this.dataParser = dataParser;
|
30 |
|
|
this.buildingsToAreas = buildingsToAreas;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
/// <summary>
|
35 |
|
|
/// Extracts list of feature vectors from parsed info objects.
|
36 |
|
|
/// </summary>
|
37 |
|
|
/// <param name="weatherInfos">List of weather info objects.</param>
|
38 |
|
|
/// <param name="activityInfos">List of info objects about activities at the site.</param>
|
39 |
|
|
/// <returns>A list of feature vectors for model training.</returns>
|
40 |
|
|
public IEnumerable<ModelInput> PrepareModelInput(int area, DateTime startDate, DateTime endDate, int interval = 1, bool wholeDay = true)
|
41 |
|
|
{
|
42 |
|
|
dataParser.Parse(startDate, endDate, interval, wholeDay);
|
43 |
|
|
List<string> buildings = new List<string>();
|
44 |
|
|
|
45 |
|
|
// find all buildings in area
|
46 |
|
|
foreach (KeyValuePair<string, int> kvp in buildingsToAreas)
|
47 |
|
|
{
|
48 |
|
|
if (kvp.Value == area)
|
49 |
|
|
{
|
50 |
|
|
buildings.Add(kvp.Key);
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
var res = new List<ModelInput>();
|
55 |
|
|
// TODO use iterators to access records about attendance and weather together
|
56 |
|
|
foreach (Parser.OutputInfo.ActivityInfo val in dataParser.AttendanceList) {
|
57 |
|
|
if (buildings.Contains(val.building)) {
|
58 |
|
|
res.Add(new ModelInput
|
59 |
|
|
{
|
60 |
|
|
Temp = 0,
|
61 |
|
|
Time = val.startTime,
|
62 |
|
|
// TODO convert val.amount to label
|
63 |
|
|
});
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
return res;
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
}
|