Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 22211075

Přidáno uživatelem Roman Kalivoda před více než 3 roky(ů)

Revert "Merge branch 'PredictorAPI' into 'master'"

This reverts merge request !20

Zobrazit rozdíly:

Server/ServerApp/Predictor/FeatureExtractor.cs
13 13
    /// <summary>
14 14
    /// A class responsible for preparation of features for classifiers.
15 15
    /// </summary>
16
    class FeatureExtractor
16
    public class FeatureExtractor
17 17
    {
18 18
        /// <summary>
19 19
        /// A DataParser instance used to access info objects.
20 20
        /// </summary>
21
        private readonly IDataParser DataParser;
21
        private readonly IDataParser dataParser;
22 22

  
23
        /// <summary>
24
        /// A configuration object of the <c>Predictor</c> package
25
        /// </summary>
26
        private PredictorConfiguration Configuration;
23
        private Dictionary<string, int> buildingsToAreas;
27 24

  
28 25
        /// <summary>
29 26
        /// Instantiates new FeatureExtractor class.
30 27
        /// </summary>
31 28
        /// <param name="dataParser">Data parser used to access training data.</param>
32
        public FeatureExtractor(IDataParser dataParser, PredictorConfiguration configuration)
29
        public FeatureExtractor(IDataParser dataParser, Dictionary<string, int> buildingsToAreas)
33 30
        {
34
            this.DataParser = dataParser;
35
            this.Configuration = configuration;
31
            this.dataParser = dataParser;
32
            this.buildingsToAreas = buildingsToAreas;
36 33
        }
37 34

  
38 35
        /// <summary>
......
44 41
        /// <param name="interval"></param>
45 42
        /// <param name="wholeDay"></param>
46 43
        /// <returns></returns>
47
        public List<ModelInput> PrepareTrainingInput(int area)
44
        public List<ModelInput> PrepareTrainingInput(int area, DateTime startDate, DateTime endDate, int interval = 1, bool wholeDay = true)
48 45
        {
46
            dataParser.Parse(startDate, endDate, interval, wholeDay);
49 47
            List<string> buildings = new List<string>();
50 48

  
51 49
            // find all buildings in area
52
            foreach (KeyValuePair<string, int> kvp in Configuration.BuildingsToAreas)
50
            foreach (KeyValuePair<string, int> kvp in buildingsToAreas)
53 51
            {
54 52
                if (kvp.Value == area)
55 53
                {
......
58 56
            }
59 57

  
60 58
            var res = new List<ModelInput>();
61
            foreach (WeatherInfo val in DataParser.WeatherList)
59
            foreach (WeatherInfo val in dataParser.WeatherList)
62 60
            {
63 61
                res.Add(new ModelInput
64 62
                {
65
                    Time = val.startTime,
66 63
                    Temp = (float)val.temp,
67
                    Hour = val.startTime.Hour,
64
                    Time = val.startTime,
68 65
                    Wind = (float)val.wind,
69 66
                    Rain = (float)val.rain,
70 67
                });
71 68
            }
72 69

  
73
            List<ActivityInfo> attendance = DataParser.AttendanceList;
70
            List<ActivityInfo> attendance = dataParser.AttendanceList;
74 71
            foreach (ModelInput input in res)
75 72
            {
76 73
                List<int> amounts = new List<int>();
77 74
                List<int> maxima = new List<int>();
78 75
                foreach (string building in buildings)
79 76
                {
80
                    List<ActivityInfo> temp = attendance.Where(activity => activity.building.Equals(building)).ToList();
81
                    amounts.Add(temp.Where(activity => activity.startTime.Equals(input.Time)).Select(activity => activity.amount).First());
82
                    maxima.Add(temp.Select(activity => activity.amount).Max());
77

  
78
                    amounts.Add(attendance.Where(activity => activity.building.Equals(building) && activity.startTime.Equals(input.Time)).Select(activity => activity.amount).First());
79
                    maxima.Add(attendance.Where(activity => activity.building.Equals(building)).Select(activity => activity.amount).Max());
83 80
                }
84 81
                double ratio = amounts.Sum() / (double)maxima.Sum();
85 82
                input.Label = RatioToLabel(ratio);
......
93 90
            if (ratio < 0.1f)
94 91
            {
95 92
                return "10%";
96
            }
97
            else if (ratio < 0.2f)
93
            } else if (ratio < 0.2f)
98 94
            {
99 95
                return "20%";
100
            }
101
            else if (ratio < 0.3f)
96
            } else if (ratio < 0.3f)
102 97
            {
103 98
                return "30%";
104
            }
105
            else if (ratio < 0.4f)
99
            } else if (ratio < 0.4f)
106 100
            {
107 101
                return "40%";
108
            }
109
            else if (ratio < 0.5f)
102
            } else if (ratio < 0.5f)
110 103
            {
111 104
                return "50%";
112
            }
113
            else if (ratio < 0.6f)
105
            } else if (ratio < 0.6f)
114 106
            {
115 107
                return "60%";
116
            }
117
            else if (ratio < 0.7f)
118
            {
108
            } else if(ratio < 0.7f) {
119 109
                return "70%";
120
            }
121
            else if (ratio < 0.8f)
110
            } else if (ratio < 0.8f)
122 111
            {
123 112
                return "80%";
124
            }
125
            else if (ratio < 0.9f)
113
            } else if (ratio < 0.9f)
126 114
            {
127 115
                return "90%";
128
            }
129
            else
116
            } else
130 117
            {
131 118
                return "100%";
132 119
            }
133 120
        }
134 121

  
135
        internal double LabelToRatio(string label)
122
        private double LabelToRatio(string label)
136 123
        {
137
            if (label.Equals("10%"))
138
            {
124
            if (label.Equals("10%")) {
139 125
                return 0.1f;
140 126
            }
141
            else if (label.Equals("20%"))
142
            {
127
            else if (label.Equals("20%"))  {
143 128
                return 0.2f;
144 129
            }
145
            else if (label.Equals("30%"))
146
            {
130
            else if (label.Equals("30%")) {
147 131
                return 0.3f;
148 132
            }
149
            else if (label.Equals("40%"))
150
            {
133
            else if (label.Equals("40%")) {
151 134
                return 0.4f;
152 135
            }
153
            else if (label.Equals("50%"))
154
            {
136
            else if (label.Equals("50%")) {
155 137
                return 0.5f;
156 138
            }
157
            else if (label.Equals("60%"))
158
            {
139
            else if (label.Equals("60%")) {
159 140
                return 0.6f;
160 141
            }
161
            else if (label.Equals("70%"))
162
            {
142
            else if (label.Equals("70%")) {
163 143
                return 0.7f;
164 144
            }
165
            else if (label.Equals("80%"))
166
            {
145
            else if (label.Equals("80%")) {
167 146
                return 0.8f;
168 147
            }
169
            else if (label.Equals("90%"))
170
            {
148
            else if (label.Equals("90%")) {
171 149
                return 0.9f;
172 150
            }
173 151
            else

Také k dispozici: Unified diff