Projekt

Obecné

Profil

Stáhnout (2.61 KB) Statistiky
| Větev: | Tag: | Revize:
1
using ServerApp.DataDownload;
2
using ServerApp.Predictor;
3
using System;
4
using System.Collections.Generic;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8

    
9
namespace ServerApp.User
10
{
11
	
12

    
13
	public class CommandsAcceptor
14
	{
15
		private DataDownloader dd;
16
		private IPredictionController model;
17

    
18
		public CommandsAcceptor(DataDownloader dd, IPredictionController controller)
19
		{
20
			this.dd = dd;
21
			this.model = controller;
22
		}
23

    
24
		public void AcceptCommand()
25
		{
26
			while (true) {
27
				string command = Console.ReadLine();
28
				Console.WriteLine("received admin command: " + command);
29
				Command c = ParseString(command);
30
				CheckCommand(c);
31
				//Program.NotifyUserMessage(command);
32
			}
33
		}
34

    
35
		private static Command ParseString(string str)
36
		{
37

    
38
			string[] splits = str.Trim().Split(' ');
39
			Command command = new Command();
40

    
41
			command.WholeCommand = str.Trim();
42
			command.MainCommand = splits[0];
43

    
44
			for(int i = 1; i < splits.Length; i++)
45
			{
46

    
47
				string current = splits[i];
48
				if (current.StartsWith("-"))
49
				{
50
					command.AddFlag(current.Substring(1));
51
				}
52
				else
53
				{
54
					command.AddData(current);
55
				}
56
			}
57

    
58
			return command;
59
		}
60

    
61
		private void CheckCommand(Command c)
62
		{
63

    
64
			switch (c.MainCommand)
65
			{
66
				case "data":
67
					HandleDataCommand(c);
68
					break;
69
				case "model":
70
					HandleModelCommand(c);
71
					break;
72
				case "help":
73
					HandleHelpCommand(c);
74
					break;
75
				default:
76
					PrintUnknown(c.MainCommand);
77
					break;
78
			}
79
		}
80

    
81
		private void PrintUnknown(string command)
82
		{
83
			Console.WriteLine("Unknown command: " + command);
84
		}
85

    
86
		private void HandleDataCommand(Command c)
87
		{
88
			// data -list
89
			// data -dl 1-2019 12-2020
90

    
91
			if(c.WholeCommand.Equals("data -list"))
92
			{
93
				Console.WriteLine("Listing all downloaded data files...");
94
				
95
			}
96
			else if (c.FlagsAndData.ContainsKey("dl"))
97
			{
98
				List<string> dates = c.FlagsAndData["dl"];
99
				if (dates.Count != 2)
100
				{
101
					Console.WriteLine("2 date arguments needed!");
102
					return;
103
				}
104

    
105
				Date start = Date.ParseDate(dates[0]);
106
				Date end = Date.ParseDate(dates[1]);
107

    
108
				if (start == null || end == null)
109
				{
110
					Console.WriteLine("Date parsing was not successful. Please ensure you enter the dates in the following format: 1-2020. Month must be greater than zero.");
111
					return;
112
				}
113

    
114
				Console.WriteLine("Downloading data from " + start.ToString() + " to " + end.ToString());
115
			}
116
		}
117

    
118
		private void HandleModelCommand(Command c)
119
		{
120
			// model -files
121
			// model -retrain
122
			// model -rollback
123
		}
124

    
125
		private void HandleHelpCommand(Command c)
126
		{
127
			Console.WriteLine("help.");
128
		}
129

    
130
		private void PrintUsage(Command c)
131
		{
132
			
133
		}
134
	}
135
}
(2-2/2)