Revize 4a417b8b
Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)
Server/ServerApp/DataDownload/DataDownloader.cs | ||
---|---|---|
28 | 28 |
XML, JSON, CSV |
29 | 29 |
} |
30 | 30 |
|
31 |
public enum TimeSpan |
|
32 |
{ |
|
33 |
|
|
34 |
} |
|
35 |
|
|
36 | 31 |
/// <summary> |
37 | 32 |
/// This class takes care of downloading of data. Download happens from http://openstore.zcu.cz/. |
38 | 33 |
/// </summary> |
... | ... | |
65 | 60 |
// a shortcut to writing Path.DirectorySeparatorChar |
66 | 61 |
private char sep = Path.DirectorySeparatorChar; |
67 | 62 |
|
68 |
public DataDownloader(string rootDataDir, string website, string namingConvention) // todo take naming conventons specifiaction into account |
|
63 |
private List<string> separatedFileName; |
|
64 |
private List<string> variablesInsertions; |
|
65 |
private List<char> nameTurns; |
|
66 |
|
|
67 |
public DataDownloader(string rootDataDir, string website, string namingConvention) // todo: take naming conventons specifiaction into account |
|
69 | 68 |
{ |
70 | 69 |
// initialize all needed variables: |
71 | 70 |
|
72 | 71 |
DataSubDirectories = new Dictionary<DataType, string>(); |
73 |
|
|
74 |
Console.WriteLine(Directory.GetCurrentDirectory()); |
|
72 |
|
|
73 |
//Console.WriteLine(Directory.GetCurrentDirectory());
|
|
75 | 74 |
site = website;//"http://openstore.zcu.cz/"; |
75 |
|
|
76 |
ParseNaming(namingConvention); |
|
76 | 77 |
dataStr = "OD_ZCU_"; |
77 | 78 |
|
78 | 79 |
RootDataDirectory = rootDataDir;//$"..{sep}..{sep}..{sep}data{sep}auto"; |
... | ... | |
81 | 82 |
webClient = new WebClient(); |
82 | 83 |
} |
83 | 84 |
|
85 |
private void ParseNaming(string namingConvention) |
|
86 |
{ |
|
87 |
separatedFileName = new List<string>(); |
|
88 |
variablesInsertions = new List<string>(); |
|
89 |
nameTurns = new List<char>(); |
|
90 |
|
|
91 |
string currPart = ""; |
|
92 |
string currVar = ""; |
|
93 |
bool readingNormal = true; |
|
94 |
foreach (char c in namingConvention) |
|
95 |
{ |
|
96 |
if (c == '{') |
|
97 |
{ |
|
98 |
AddToNameParts(currPart); |
|
99 |
readingNormal = false; |
|
100 |
currPart = ""; |
|
101 |
} |
|
102 |
else if (c == '}') |
|
103 |
{ |
|
104 |
AddToVariables(currVar); |
|
105 |
readingNormal = true; |
|
106 |
currVar = ""; |
|
107 |
} |
|
108 |
else |
|
109 |
{ |
|
110 |
// normal char |
|
111 |
if (readingNormal) |
|
112 |
currPart += c; |
|
113 |
else |
|
114 |
currVar += c; |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
// add the rest if there is any: |
|
119 |
if (readingNormal) |
|
120 |
AddToNameParts(currPart); |
|
121 |
else |
|
122 |
AddToVariables(currVar); |
|
123 |
|
|
124 |
Console.WriteLine(); |
|
125 |
} |
|
126 |
|
|
127 |
private void AddToNameParts(string s) |
|
128 |
{ |
|
129 |
if (s.Length > 0) |
|
130 |
{ |
|
131 |
separatedFileName.Add(s); |
|
132 |
nameTurns.Add('n'); |
|
133 |
} |
|
134 |
|
|
135 |
} |
|
136 |
|
|
137 |
private void AddToVariables(string s) |
|
138 |
{ |
|
139 |
if (s.Length > 0) |
|
140 |
{ |
|
141 |
variablesInsertions.Add(s); |
|
142 |
nameTurns.Add('v'); |
|
143 |
} |
|
144 |
|
|
145 |
} |
|
146 |
|
|
147 |
|
|
148 |
private string BuildDownloadedName(DataType type, DataFormat format, int year, int month) |
|
149 |
{ |
|
150 |
string nameZip = ""; |
|
151 |
|
|
152 |
int partInd = 0; |
|
153 |
int varInd = 0; |
|
154 |
for(int i = 0; i < nameTurns.Count; i++) |
|
155 |
{ |
|
156 |
if (nameTurns[i] == 'n') |
|
157 |
{ |
|
158 |
nameZip += separatedFileName[partInd]; |
|
159 |
partInd++; |
|
160 |
} |
|
161 |
else if(nameTurns[i] == 'v') |
|
162 |
{ |
|
163 |
string add = ""; |
|
164 |
switch (variablesInsertions[varInd]) |
|
165 |
{ |
|
166 |
case "type": |
|
167 |
add = "" + type; |
|
168 |
break; |
|
169 |
case "month": |
|
170 |
add = month < 10 ? "0" + month : "" + month; |
|
171 |
break; |
|
172 |
case "year": |
|
173 |
add = "" + year; |
|
174 |
break; |
|
175 |
case "format": |
|
176 |
add = "" + format; |
|
177 |
break; |
|
178 |
default: throw new Exception("Config file error - naming conventions can only contain variables with following names: type, month, year, format"); |
|
179 |
} |
|
180 |
nameZip += add; |
|
181 |
varInd++; |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
return nameZip; |
|
186 |
} |
|
187 |
|
|
84 | 188 |
/// <summary> |
85 | 189 |
/// Downloads a specific archive. |
86 | 190 |
/// </summary> |
... | ... | |
97 | 201 |
// Prepare the url string to be downloaded from: |
98 | 202 |
string monthStr = month < 10 ? "0" + month : "" + month; |
99 | 203 |
string yearStr = "" + year; |
100 |
|
|
101 | 204 |
string monthYr = monthStr + "_" + yearStr; |
102 |
string url = site + "/" + dataStr + monthYr + "/" + dataStr + type + "_" + monthYr + "_" + format + ".zip"; |
|
103 |
string nameZip = dataStr + type + "_" + monthYr + "_" + format + ".zip"; |
|
205 |
|
|
206 |
|
|
207 |
string nameZip = BuildDownloadedName(type, format, year, month);//dataStr + type + "_" + monthYr + "_" + format + ".zip"; |
|
208 |
string url = site + "/" + dataStr + monthYr + "/" + nameZip;//+ dataStr + type + "_" + monthYr + "_" + format + ".zip"; |
|
209 |
|
|
104 | 210 |
string nameFolder = RootDataDirectory + sep + type + sep; //+ dataStr + type + "_" + monthYr + "_" + format; |
105 | 211 |
|
106 | 212 |
try |
... | ... | |
208 | 314 |
currentDate = nextDate; |
209 | 315 |
|
210 | 316 |
|
211 |
} while (currentDate != endDate);
|
|
317 |
} while (currentDate <= endDate);
|
|
212 | 318 |
|
213 | 319 |
|
214 | 320 |
|
... | ... | |
229 | 335 |
throw new NotImplementedException(); |
230 | 336 |
} |
231 | 337 |
|
232 |
public List<string> GetData(string subDirectory, int startYear, int endYear, int startMonth, int endMonth)
|
|
338 |
public List<string> GetData(string subDirectory, Date startDate, Date endDate)
|
|
233 | 339 |
{ |
340 |
string[] files = Directory.GetFiles(subDirectory); |
|
341 |
for(int i = 0; i < files.Length; i++) |
|
342 |
{ |
|
343 |
|
|
344 |
} |
|
345 |
|
|
234 | 346 |
throw new NotImplementedException(); |
235 | 347 |
} |
236 | 348 |
|
Server/ServerApp/Program.cs | ||
---|---|---|
2 | 2 |
using ServerApp.DataDownload; |
3 | 3 |
using ServerApp.Parser.Parsers; |
4 | 4 |
using ServerApp.Predictor; |
5 |
using ServerApp.User; |
|
5 | 6 |
using System; |
6 | 7 |
using System.Collections.Generic; |
7 | 8 |
using System.IO; |
9 |
using System.Threading; |
|
8 | 10 |
|
9 | 11 |
namespace ServerApp |
10 | 12 |
{ |
... | ... | |
17 | 19 |
public string Port { get; set; } |
18 | 20 |
} |
19 | 21 |
|
20 |
class Program |
|
22 |
public class Program
|
|
21 | 23 |
{ |
22 | 24 |
|
23 |
|
|
25 |
public static void NotifyUserMessage(string message) |
|
26 |
{ |
|
27 |
Console.WriteLine("Received user message: " + message); |
|
28 |
} |
|
24 | 29 |
|
25 | 30 |
static void Main(string[] args) |
26 | 31 |
{ |
... | ... | |
32 | 37 |
return; |
33 | 38 |
} |
34 | 39 |
|
40 |
// create a thread for commands accepting: |
|
41 |
//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand); |
|
42 |
//inputThread.Start(); |
|
43 |
|
|
35 | 44 |
|
36 | 45 |
|
37 | 46 |
//DataParser p = new DataParser("data/"); |
... | ... | |
80 | 89 |
|
81 | 90 |
// test - connection: |
82 | 91 |
//AsynchronousSocketListener asl = new AsynchronousSocketListener(); |
83 |
// asl.StartListening();
|
|
92 |
//asl.StartListening(); |
|
84 | 93 |
|
85 | 94 |
|
86 | 95 |
//NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier(); |
Server/ServerApp/ServerApp.csproj | ||
---|---|---|
158 | 158 |
<Compile Include="Predictor\NaiveBayesClassifier.cs" /> |
159 | 159 |
<Compile Include="Program.cs" /> |
160 | 160 |
<Compile Include="Properties\AssemblyInfo.cs" /> |
161 |
<Compile Include="User\CommandsAcceptor.cs" /> |
|
161 | 162 |
</ItemGroup> |
162 | 163 |
<ItemGroup> |
163 | 164 |
<None Include="App.config" /> |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace ServerApp.User |
|
8 |
{ |
|
9 |
public class CommandsAcceptor |
|
10 |
{ |
|
11 |
|
|
12 |
public static void AcceptCommand() |
|
13 |
{ |
|
14 |
while (true) { |
|
15 |
string command = Console.ReadLine(); |
|
16 |
Program.NotifyUserMessage(command); |
|
17 |
} |
|
18 |
} |
|
19 |
} |
|
20 |
} |
Server/ServerApp/server_config | ||
---|---|---|
1 |
|
|
2 | 1 |
# |
2 |
# Tri Musketyri, ASWI 2021 |
|
3 | 3 |
# This is the server configuration file. See [wiki_site] for detailed information about its structure. |
4 | 4 |
# Pass this file as an argument to the server program when launching it. |
5 | 5 |
# |
... | ... | |
11 | 11 |
http://openstore.zcu.cz/ |
12 | 12 |
|
13 | 13 |
# the naming convention for files stored at the site to download from: |
14 |
# variables in this string must keep their name, cannot be excluded and others cannot be added. They must be enclosed in {} brackets |
|
15 |
# {} characters are treated as special characters and cannot be used as a part of the name |
|
14 | 16 |
!naming_convention! |
15 | 17 |
OD_ZCU_{type}_{month}_{year}_{format}.zip |
16 | 18 |
|
Také k dispozici: Unified diff
Re #8691. Url config improvements + thread for commands accepting prepared.