Revize c4383c00
Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)
Server/ServerApp/DataDownload/Date.cs | ||
---|---|---|
38 | 38 |
return new Date(newMonth, newYear); |
39 | 39 |
} |
40 | 40 |
|
41 |
/// <summary> |
|
42 |
/// Parses the date given in format: 1-2020 |
|
43 |
/// </summary> |
|
44 |
/// <param name="str">The string to parse</param> |
|
45 |
/// <returns>A new date</returns> |
|
46 |
public static Date ParseDate(string str) |
|
47 |
{ |
|
48 |
|
|
49 |
uint month, year; |
|
50 |
|
|
51 |
string ds = str.Trim(); |
|
52 |
string[] splits = ds.Split('-'); |
|
53 |
|
|
54 |
if(splits.Length != 2) |
|
55 |
{ |
|
56 |
Console.WriteLine("Unknown date format. Must be e.g. 1-2020."); |
|
57 |
return null; |
|
58 |
} |
|
59 |
|
|
60 |
bool monthOk = uint.TryParse(splits[0], out month); |
|
61 |
bool yearOk = uint.TryParse(splits[1], out year); |
|
62 |
|
|
63 |
if(!monthOk || !yearOk) |
|
64 |
{ |
|
65 |
Console.WriteLine("Unknown date format. Must be e.g. 1-2020."); |
|
66 |
return null; |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
try |
|
71 |
{ |
|
72 |
Date d = new Date(month, year); |
|
73 |
return d; |
|
74 |
} |
|
75 |
catch (Exception ex) |
|
76 |
{ |
|
77 |
return null; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
return null; |
|
82 |
} |
|
83 |
|
|
41 | 84 |
|
42 | 85 |
#region OVERRIDEN METHODS FOR OF THE OBJECT CLASS |
43 | 86 |
public override bool Equals(object obj) |
Server/ServerApp/Program.cs | ||
---|---|---|
25 | 25 |
public class Program |
26 | 26 |
{ |
27 | 27 |
|
28 |
public static void NotifyUserMessage(string message)
|
|
28 |
public void NotifyUserMessage(string message) |
|
29 | 29 |
{ |
30 | 30 |
Console.WriteLine("Received user message: " + message); |
31 | 31 |
} |
... | ... | |
42 | 42 |
return; |
43 | 43 |
} |
44 | 44 |
|
45 |
// commands accepting test |
|
46 |
//create a thread for commands accepting: |
|
47 |
//Thread inputThread = new Thread(CommandsAcceptor.AcceptCommand); |
|
48 |
//inputThread.Start(); |
|
45 |
|
|
49 | 46 |
|
50 | 47 |
|
51 | 48 |
// is this obsolete? |
... | ... | |
78 | 75 |
//parse(new DateTime(2019, 10, 5), , interval = 1, wholeDay = true) |
79 | 76 |
|
80 | 77 |
|
78 |
// commands accepting test |
|
79 |
// create a thread for commands accepting: |
|
80 |
CommandsAcceptor ca = new CommandsAcceptor(dd, controller); |
|
81 |
Thread inputThread = new Thread(ca.AcceptCommand); |
|
82 |
inputThread.Start(); |
|
83 |
|
|
81 | 84 |
// connection test |
82 | 85 |
ConnectionTest(controller, config); |
86 |
|
|
87 |
|
|
83 | 88 |
|
84 | 89 |
|
85 | 90 |
Console.ReadLine(); |
Server/ServerApp/User/Command.cs | ||
---|---|---|
6 | 6 |
|
7 | 7 |
namespace ServerApp.User |
8 | 8 |
{ |
9 |
public enum Commands |
|
10 |
{ |
|
11 |
RETRAIN, ROLLBACK, DATA_LIST, NEW_DATA, HELP |
|
12 |
} |
|
13 | 9 |
|
14 | 10 |
public class Command |
15 | 11 |
{ |
12 |
public string WholeCommand { get; set; } |
|
16 | 13 |
public string MainCommand { get; set; } |
17 | 14 |
public Dictionary<string, List<string>> FlagsAndData { get; } |
18 | 15 |
private string lastFlag; |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
1 |
using System; |
|
1 |
using ServerApp.DataDownload; |
|
2 |
using ServerApp.Predictor; |
|
3 |
using System; |
|
2 | 4 |
using System.Collections.Generic; |
3 | 5 |
using System.Linq; |
4 | 6 |
using System.Text; |
... | ... | |
10 | 12 |
|
11 | 13 |
public class CommandsAcceptor |
12 | 14 |
{ |
15 |
private DataDownloader dd; |
|
16 |
private IPredictionController model; |
|
13 | 17 |
|
14 |
public static void AcceptCommand() |
|
18 |
public CommandsAcceptor(DataDownloader dd, IPredictionController controller) |
|
19 |
{ |
|
20 |
this.dd = dd; |
|
21 |
this.model = controller; |
|
22 |
} |
|
23 |
|
|
24 |
public void AcceptCommand() |
|
15 | 25 |
{ |
16 | 26 |
while (true) { |
17 | 27 |
string command = Console.ReadLine(); |
28 |
Console.WriteLine("received admin command: " + command); |
|
18 | 29 |
Command c = ParseString(command); |
19 | 30 |
CheckCommand(c); |
20 |
Program.NotifyUserMessage(command); |
|
31 |
//Program.NotifyUserMessage(command);
|
|
21 | 32 |
} |
22 | 33 |
} |
23 | 34 |
|
24 | 35 |
private static Command ParseString(string str) |
25 | 36 |
{ |
26 |
string[] splits = str.Split(' '); |
|
37 |
|
|
38 |
string[] splits = str.Trim().Split(' '); |
|
27 | 39 |
Command command = new Command(); |
28 | 40 |
|
41 |
command.WholeCommand = str.Trim(); |
|
29 | 42 |
command.MainCommand = splits[0]; |
30 | 43 |
|
31 | 44 |
for(int i = 1; i < splits.Length; i++) |
... | ... | |
45 | 58 |
return command; |
46 | 59 |
} |
47 | 60 |
|
48 |
private static void CheckCommand(Command c)
|
|
61 |
private void CheckCommand(Command c) |
|
49 | 62 |
{ |
50 |
Console.WriteLine(c); |
|
51 | 63 |
|
52 | 64 |
switch (c.MainCommand) |
53 | 65 |
{ |
54 |
case "data": break; |
|
55 |
case "model": break; |
|
56 |
case "help": break; |
|
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; |
|
57 | 78 |
} |
58 | 79 |
} |
59 | 80 |
|
60 |
private void PrintUsage() |
|
81 |
private void PrintUnknown(string command) |
|
82 |
{ |
|
83 |
Console.WriteLine("Unknown command: " + command); |
|
84 |
} |
|
85 |
|
|
86 |
private void HandleDataCommand(Command c) |
|
61 | 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]); |
|
62 | 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 |
|
|
63 | 133 |
} |
64 | 134 |
} |
65 | 135 |
} |
Také k dispozici: Unified diff
Re #8942. Started implementing admin commands.