first commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31112.23
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BosServerConvert", "BosServerConvert\BosServerConvert.csproj", "{CEBBF847-6041-4557-B2FD-FBDCE7CDEE50}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils-IoT", "..\..\Utils\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{E2B3A4E8-A404-46E9-8FCA-E7183A61EAB3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils", "..\..\Utils\Utils\Utils\Utils.csproj", "{6EFF890D-4C1D-495F-9BC6-EC1DB4CC5325}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "litjson", "..\..\Librarys\litjson\litjson\litjson.csproj", "{E94D6477-77C9-4722-9306-1C9EF1C86C99}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectorDbMysql", "..\..\Utils\ConnectorDbMysql\ConnectorDbMysql\ConnectorDbMysql.csproj", "{BC10C8C2-6108-486E-94DE-453720E84868}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bot-Utils", "..\..\Utils\Bot-Utils\Bot-Utils\Bot-Utils.csproj", "{AF055E18-51B7-46A0-A0B6-C0E6EED4D95A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BosServerDatatypes", "..\BosServerDatatypes\BosServerDatatypes.csproj", "{48851AED-A7A2-43A6-8B90-E9917D16DC19}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CEBBF847-6041-4557-B2FD-FBDCE7CDEE50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CEBBF847-6041-4557-B2FD-FBDCE7CDEE50}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CEBBF847-6041-4557-B2FD-FBDCE7CDEE50}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CEBBF847-6041-4557-B2FD-FBDCE7CDEE50}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E2B3A4E8-A404-46E9-8FCA-E7183A61EAB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E2B3A4E8-A404-46E9-8FCA-E7183A61EAB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E2B3A4E8-A404-46E9-8FCA-E7183A61EAB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E2B3A4E8-A404-46E9-8FCA-E7183A61EAB3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6EFF890D-4C1D-495F-9BC6-EC1DB4CC5325}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6EFF890D-4C1D-495F-9BC6-EC1DB4CC5325}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6EFF890D-4C1D-495F-9BC6-EC1DB4CC5325}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6EFF890D-4C1D-495F-9BC6-EC1DB4CC5325}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E94D6477-77C9-4722-9306-1C9EF1C86C99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E94D6477-77C9-4722-9306-1C9EF1C86C99}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E94D6477-77C9-4722-9306-1C9EF1C86C99}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E94D6477-77C9-4722-9306-1C9EF1C86C99}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BC10C8C2-6108-486E-94DE-453720E84868}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC10C8C2-6108-486E-94DE-453720E84868}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC10C8C2-6108-486E-94DE-453720E84868}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC10C8C2-6108-486E-94DE-453720E84868}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AF055E18-51B7-46A0-A0B6-C0E6EED4D95A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AF055E18-51B7-46A0-A0B6-C0E6EED4D95A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF055E18-51B7-46A0-A0B6-C0E6EED4D95A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF055E18-51B7-46A0-A0B6-C0E6EED4D95A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48851AED-A7A2-43A6-8B90-E9917D16DC19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48851AED-A7A2-43A6-8B90-E9917D16DC19}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48851AED-A7A2-43A6-8B90-E9917D16DC19}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48851AED-A7A2-43A6-8B90-E9917D16DC19}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {EC08A76A-6496-4AFF-AB3C-D83912F25618}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Utils\Bot-Utils\Bot-Utils\Bot-Utils.csproj" />
|
||||
<ProjectReference Include="..\..\..\Utils\ConnectorDbMysql\ConnectorDbMysql\ConnectorDbMysql.csproj" />
|
||||
<ProjectReference Include="..\..\..\Utils\Utils-IoT\Utils-IoT\Utils-IoT.csproj" />
|
||||
<ProjectReference Include="..\..\BosServerDatatypes\BosServerDatatypes.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,259 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Pocsag.BosServerDatatypes.Influx;
|
||||
using BlubbFish.IoT.Pocsag.BosServerDatatypes.Json;
|
||||
using BlubbFish.IoT.Pocsag.BosServerDatatypes.Mqtt;
|
||||
using BlubbFish.IoT.Pocsag.BosServerDatatypes.MysqlTables;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Bots;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BosServerConvert {
|
||||
class Program : ABot {
|
||||
private readonly ABackend mysql;
|
||||
private readonly Dictionary<String, String> bosconf;
|
||||
|
||||
//private List<TelegramStorage> mysqlTableMessage;
|
||||
private List<PocsagRecords> mysqlTableRic;
|
||||
//private List<PocsagParsed> pocsagTable;
|
||||
private SortedDictionary<String, RicData> ricData;
|
||||
//private List<String> influxTable;
|
||||
//private readonly Dictionary<String, (String, RicDescription)> rics = new Dictionary<String, (String, RicDescription)>();
|
||||
|
||||
|
||||
static void Main(String[] args) => new Program(args, false, "bsconvert");
|
||||
public Program(String[] args, Boolean fileLogging, String configSearchPath) : base(args, fileLogging, configSearchPath) {
|
||||
this.mysql = ABackend.GetInstance(InIReader.GetInstance("settings").GetSection("storage"));
|
||||
this.bosconf = InIReader.GetInstance("settings").GetSection("bosserverparser");
|
||||
|
||||
Console.WriteLine("Wait for mysql");
|
||||
while(!this.mysql.IsConnected) {
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
Console.WriteLine("Mysql is now connected.");
|
||||
Console.WriteLine("\n\n");
|
||||
|
||||
Console.WriteLine("Load data from mysql...");
|
||||
DateTime start = DateTime.Now;
|
||||
this.LoadRicList();
|
||||
DateTime stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("Mysql items: " + this.mysqlTableRic.Count + "\n\n");
|
||||
|
||||
Console.WriteLine("Parse data...");
|
||||
start = DateTime.Now;
|
||||
this.ParseRics();
|
||||
stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("Pocsag items: " + this.ricData.Count + "\n\n");
|
||||
|
||||
Console.WriteLine("Write to output file...");
|
||||
start = DateTime.Now;
|
||||
this.WriteFileRics();
|
||||
stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("\n\n");
|
||||
|
||||
/*Console.WriteLine("Load data from mysql...");
|
||||
DateTime start = DateTime.Now;
|
||||
this.LoadMessageList();
|
||||
DateTime stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("Mysql items: " + this.mysqlTableMessage.Count + "\n\n");
|
||||
|
||||
Console.WriteLine("Parse data...");
|
||||
start = DateTime.Now;
|
||||
this.ParseMessage();
|
||||
stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("Pocsag items: " + this.pocsagTable.Count + "\n\n");
|
||||
|
||||
Console.WriteLine("Convert to Influx...");
|
||||
start = DateTime.Now;
|
||||
this.GenerateInflux();
|
||||
stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("Influx items: " + this.influxTable.Count + "\n\n");
|
||||
|
||||
Console.WriteLine("Write to output file...");
|
||||
start = DateTime.Now;
|
||||
this.WriteFileMessage();
|
||||
stop = DateTime.Now;
|
||||
Console.WriteLine("Takes " + (stop - start).TotalSeconds + "s");
|
||||
Console.WriteLine("\n\n");*/
|
||||
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
/*private void WriteFileMessage() {
|
||||
StreamWriter file = new StreamWriter(this.bosconf["outputfile"], false, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)) {
|
||||
AutoFlush = true
|
||||
};
|
||||
|
||||
foreach(String item in this.influxTable) {
|
||||
file.Write(item+"\n");
|
||||
}
|
||||
|
||||
file.Flush();
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
}*/
|
||||
|
||||
private void WriteFileRics() {
|
||||
JsonWriter m = new JsonWriter();
|
||||
m.PrettyPrint = true;
|
||||
JsonMapper.ToJson(this.ricData, m);
|
||||
File.WriteAllText("ric.json", m.ToString());
|
||||
}
|
||||
|
||||
/*private void GenerateInflux() {
|
||||
this.influxTable = new List<String>();
|
||||
foreach(PocsagParsed item in this.pocsagTable) {
|
||||
this.influxTable.Add(new Bosmon(item, true).ToInfluxString());
|
||||
}
|
||||
this.pocsagTable.Clear();
|
||||
}*/
|
||||
|
||||
/*private void ParseMessage() {
|
||||
this.pocsagTable = new List<PocsagParsed>();
|
||||
Int32 time = 0;
|
||||
Int32 often = 0;
|
||||
foreach(TelegramStorage item in this.mysqlTableMessage) {
|
||||
if(item.Address.Length != 8) {
|
||||
Console.Error.WriteLine("item " + item + " is not valied");
|
||||
continue;
|
||||
}
|
||||
if(time != item.Timestamp) {
|
||||
time = item.Timestamp;
|
||||
often = 0;
|
||||
} else {
|
||||
often++;
|
||||
}
|
||||
PocsagHttp p = new PocsagHttp(item.Address.Substring(7, 1), item.Flags.ToString(), item.Message, item.Type.ToString(), item.Address.Substring(0, 7), item.Timestamp+0.01*often);
|
||||
|
||||
String funktion = this.ParseFunction(p.Function);
|
||||
(String name, RicDescription ric) = this.ParseRic(p.Address);
|
||||
GeoData geo = this.ParseLocation(p.Message, item.Extensions);
|
||||
Boolean sendonline = this.ParseFilter(p.Message, ric, p.Address);
|
||||
Boolean isprivate = this.ParsePrivate(p.Address);
|
||||
|
||||
this.pocsagTable.Add(new PocsagParsed(p, funktion, name, ric, geo, sendonline, isprivate, p.Date));
|
||||
}
|
||||
this.mysqlTableMessage.Clear();
|
||||
}*/
|
||||
|
||||
private void ParseRics() {
|
||||
this.ricData = new SortedDictionary<String, RicData>();
|
||||
foreach(PocsagRecords item in this.mysqlTableRic) {
|
||||
if(!this.ricData.ContainsKey(item.Address)) {
|
||||
this.ricData.Add(item.Address.Substring(0,7), new RicData(item.Location, item.ShortDescription, item.LongDescription));
|
||||
}
|
||||
}
|
||||
this.mysqlTableRic.Clear();
|
||||
}
|
||||
|
||||
/*private Boolean ParsePrivate(String address) => this.bosconf["special-ric"].Split(";").Contains(address);*/
|
||||
|
||||
/*private Boolean ParseFilter(String message, RicDescription ric, String address) {
|
||||
if(ric != null && ric.LongDescription.ToLower() == "idea") {
|
||||
return false;
|
||||
} else if(ric != null && ric.LongDescription.ToLower() == "leer") {
|
||||
return false;
|
||||
} else if(message == "" && ric is null) {
|
||||
return false;
|
||||
}
|
||||
foreach(KeyValuePair<String, String> item in InIReader.GetInstance("settings").GetSection("filter")) {
|
||||
String[] a = item.Value.Split("|");
|
||||
switch(a[0]) {
|
||||
case "address":
|
||||
if(address.StartsWith(a[1])) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "message":
|
||||
if(message == a[1]) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
|
||||
/*private GeoData ParseLocation(String message, String extensions) {
|
||||
Match m = Regex.Match(message, @"#C(?<lon>[0-9\.]+),(?<lat>[0-9\.]+)#");
|
||||
if(m.Success) {
|
||||
if(Double.TryParse(m.Groups["lat"].Value.Insert(2, "."), NumberStyles.Float, CultureInfo.InvariantCulture, out Double lat) &&
|
||||
Double.TryParse(m.Groups["lon"].Value.Insert(2, "."), NumberStyles.Float, CultureInfo.InvariantCulture, out Double lon)) {
|
||||
return new GeoData(lat, lon);
|
||||
}
|
||||
} else {
|
||||
Match elat = Regex.Match(extensions, @"<lat>(?<lat>[0-9\.]+)</lat>");
|
||||
Match elon = Regex.Match(extensions, @"<lng>(?<lon>[0-9\.]+)</lng>");
|
||||
if(elat.Success && elon.Success) {
|
||||
if(Double.TryParse(elat.Groups["lat"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out Double lat) &&
|
||||
Double.TryParse(elon.Groups["lon"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out Double lon)) {
|
||||
return new GeoData(lat, lon);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
/*private (String, RicDescription) ParseRic(String ric) {
|
||||
if(this.rics.ContainsKey(ric)) {
|
||||
return this.rics[ric];
|
||||
} else {
|
||||
PocsagRecords ric_data = ((BlubbFish.Utils.IoT.Connector.Db.Mysql)this.mysql).LoadSingleRow<PocsagRecords>("SELECT * FROM `PocsagRecords` WHERE `Address` = CONCAT(@ric,'*');", new Dictionary<String, Object>() { { "ric", ric } });
|
||||
RicDescription desc = null;
|
||||
String text;
|
||||
|
||||
if(ric_data is null) {
|
||||
text = ric;
|
||||
} else {
|
||||
desc = new RicDescription(ric_data.Address, ric_data.Location, ric_data.ShortDescription, ric_data.LongDescription);
|
||||
List<String> text_parts = new List<String>();
|
||||
if(!(ric_data.Location is null) && ric_data.Location != "") {
|
||||
text_parts.Add(ric_data.Location);
|
||||
}
|
||||
if(!(ric_data.ShortDescription is null) && ric_data.ShortDescription != "") {
|
||||
text_parts.Add(ric_data.ShortDescription);
|
||||
}
|
||||
if(!(ric_data.LongDescription is null) && ric_data.LongDescription != "") {
|
||||
text_parts.Add("(" + ric_data.LongDescription + ")");
|
||||
}
|
||||
text = String.Join(" ", text_parts);
|
||||
}
|
||||
this.rics.Add(ric, (text, desc));
|
||||
return (text, desc);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*private String ParseFunction(String function) => function switch {
|
||||
"a" => "EIL",
|
||||
"b" => "ZEIT",
|
||||
"c" => "PROBE",
|
||||
"d" => "ENDE",
|
||||
_ => ""
|
||||
};*/
|
||||
|
||||
/*private void LoadMessageList() => this.mysqlTableMessage = ((BlubbFish.Utils.IoT.Connector.Db.Mysql)this.mysql).LoadMultiRows<TelegramStorage>("SELECT * FROM `TelegramStorage`", new Dictionary<String, Object>());*/
|
||||
|
||||
private void LoadRicList() => this.mysqlTableRic = ((BlubbFish.Utils.IoT.Connector.Db.Mysql)this.mysql).LoadMultiRows<PocsagRecords>("SELECT * FROM `PocsagRecords`", new Dictionary<String, Object>());
|
||||
|
||||
public override void Dispose() {
|
||||
if(this.mysql != null) {
|
||||
this.mysql.Dispose();
|
||||
}
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user