Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 38a18391

Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)

Re #9007. Added weather prediction website to the config file + modified method for weather predictoin download.

Zobrazit rozdíly:

Server/ServerApp/DataDownload/DataDownloader.cs
51 51
		// the main site where the data can be downloaded from
52 52
		private string site;
53 53

  
54
		// weather prediction site
55
		private string weatherPredictionSite;
56

  
54 57
		// the substring at the start of every file name
55 58
		private string dataStr;
56 59

  
......
65 68
		private List<string> variablesInsertions;
66 69
		private List<char> nameTurns;
67 70

  
68
		public DataDownloader(string rootDataDir, string website, string namingConvention) // todo: take naming conventons specifiaction into account
71
		public DataDownloader(string rootDataDir, string website, string namingConvention, string weatherPredSite) // todo: take naming conventons specifiaction into account
69 72
		{
70 73
			// initialize all needed variables:
71 74

  
72 75
			//Console.WriteLine(Directory.GetCurrentDirectory());
73 76
			site = website;//"http://openstore.zcu.cz/";
77
			weatherPredictionSite = weatherPredSite;
74 78

  
75 79
			ParseNaming(namingConvention);
76 80
			dataStr = "OD_ZCU_";
......
91 95
		public string DownloadWeatherPrediction()
92 96
		{
93 97
			// TODO either set this path as attribute or if parameter JsonParser needs an attribute that would be set through constructor
94
			string predictionSite = "http://wttr.in/Plzen,czechia?format=j1";
95

  
96
			DateTime now = DateTime.Now;
97
			WebClient webClient = new WebClient();
98
			webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
98
			//string predictionSite = "http://wttr.in/Plzen,czechia?format=j1";
99 99

  
100
			return $"data/{now.Year}{now.Month}{now.Day}.json";
100
			//DateTime now = DateTime.Now;
101
			//WebClient webClient = new WebClient();
102
			//webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
103
			
104
			try
105
			{
106
				return webClient.DownloadString(weatherPredictionSite);// $"data/{now.Year}{now.Month}{now.Day}.json";
107
			}
108
			catch(Exception e)
109
			{
110
				// this shouldn't happen
111
				Console.WriteLine("Weather prediction download failed!");
112
				return null;
113
			}
114
			
101 115
		}
102 116

  
103 117
		/// <summary>
......
223 237
						case "format":
224 238
							add = "" + format;
225 239
							break;
226
						default: throw new Exception("Config file error - naming conventions can only contain variables with following names: type, month, year, format");
240
						default: throw new Exception("Config file error - naming conventions can only contain variables with the following names: type, month, year, format");
227 241
					}
228 242
					nameZip += add;
229 243
					varInd++;
Server/ServerApp/Program.cs
21 21
		public string DataWebsite { get; set; }
22 22
		public string DownloadedFilesNaming { get; set; }
23 23
		public string DataRootDir { get; set; }
24
		public string WeatherSite { get; set; }
24 25
		public string Port { get; set; } // TODO port cannot be configurable?
25 26
	}
26 27

  
......
46 47
			// data download test
47 48
			DataDownloader dd = DataDownloadAndRetrievalTest(config);
48 49

  
50
			WeatherAsStringTest(dd);
51
			Console.ReadLine();
52

  
49 53
			// xml building test
50 54
			//XMLTest();
51 55

  
......
77 81
		private static DataDownloader DataDownloadAndRetrievalTest(Config config)
78 82
		{
79 83
			//test scenario -data download:
80
			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
84
			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming, config.WeatherSite);
81 85
			dd.OverwriteExisting = false;
82 86
			List<string> savedFiles = new List<string>();
83 87

  
......
158 162
				Console.WriteLine(w.ToString());
159 163
		}
160 164

  
165
		private static void WeatherAsStringTest(DataDownloader dd)
166
		{
167
			Console.WriteLine(dd.DownloadWeatherPrediction());
168
		}
169

  
161 170
		private static IPredictionController PredictionTest(DataDownloader dd)
162 171
		{
163 172
			// TODO nastavit čas
......
227 236
						rootPath = Path.GetFullPath(rootPath);
228 237
						extractedConfigInfo.DataRootDir = rootPath;
229 238
						break;
239
					case "!weather_site!":
240
						extractedConfigInfo.WeatherSite = lines[++i].Trim();
241
						break;
230 242
					case "!port!":
231 243
						extractedConfigInfo.Port = lines[++i].Trim();
232 244
						break;
Server/ServerApp/Properties/launchSettings.json
2 2
  "profiles": {
3 3
    "ServerApp": {
4 4
      "commandName": "Project",
5
      "commandLineArgs": "C:\\Users\\kalivoda\\University\\KIV-ASWI\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
5
      "commandLineArgs": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
6 6
    }
7 7
  }
8 8
}
Server/ServerApp/server_config
1 1
#
2 2
# Tri Musketyri, ASWI 2021
3
# This is the server configuration file. See [wiki_site] for detailed information about its structure.
3
# This is the server configuration file. See the documentation for detailed information about its structure.
4 4
# Pass this file as an argument to the server program when launching it.
5 5
#
6 6

  
7
# --- DATA DOWNLOADING CONFIGURATION ---
7
# --- DATA FILES DOWNLOADING CONFIGURATION ---
8 8

  
9 9
# the main website containing all data:
10 10
!site!
......
21 21
!data_root_dir!
22 22
.\data\auto
23 23

  
24
# --- (future) WEATHER PREDICTION DOWNLOADING CONFIGURATION ---
25
# the url to download from - must contain data in specific format, see documentation for details
26
!weather_site!
27
http://wttr.in/Plzen,czechia?format=j1
28

  
24 29

  
25 30
# --- CONNECTION CONFIGURATION ---
26 31

  

Také k dispozici: Unified diff