ASCU_ALL/Tests/Program.cs

337 lines
9.7 KiB
C#
Raw Normal View History

2020-09-04 12:49:15 +05:00
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using System;
using System.IO;
using System.Text;
using DataClients;
using System.Threading.Tasks;
using System.Threading;
using System.Linq;
using Mailing;
using System.Text.RegularExpressions;
using System.Collections.Generic;
public class CustomMath
{
public static int multiplu(int a, int b)
{
return a * b;
}
}
2020-09-04 12:49:15 +05:00
namespace Tests
{
class Program
{
static void Main(string[] args)
{
2020-11-19 16:30:38 +05:00
test11();
2020-09-04 12:49:15 +05:00
}
static void test1()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc = Encoding.GetEncoding(866);
var filec = new FileClient();
var test = filec.GetFile(DateTime.Now.AddDays(-46), 34, 0);
//var netc = new NetClient();
//var test = netc.SocketWork(NetClient.Cmd.download_nh, "20200707.230");
//var netc = new NetClient();
//var test = netc.SocketWork(NetClient.Cmd.user_flags);
Console.WriteLine(BitConverter.ToString(test).Replace("-", " "));
Console.WriteLine(enc.GetString(test));
Console.ReadKey();
}
static void test2()
{
var a = new STPClient();
var b = a.GetTechCycle(
new DateTime(2020, 07, 1),
new DateTime(2020, 07, 10),
16);
foreach (var e in b)
Console.WriteLine(e.start.ToString(@"yyyy.MM.dd HH:mm:ss") + '\t' + Names.techCycle[(ushort)e.index]);
}
static void test3()
{
var a = new STPClient();
var b = a.GetAnalogDiscret(
new DateTime(2020, 07, 14, 0, 0, 0),
new DateTime(2020, 07, 14, 23, 59, 59),
37);
foreach (var c in b.di)
{
Console.WriteLine(Names.discretFull[c.Key]);
foreach (var d in c.Value)
Console.WriteLine(d.Item1.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + d.Item2.ToString());
}
foreach (var c in b.an)
{
Console.WriteLine(Names.discretFull[c.Key]);
foreach (var d in c.Value)
Console.WriteLine(d.Item1.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + d.Item2.ToString());
}
Console.ReadKey();
}
static void test4()
{
var a = new STPClient();
var ts = new DateTime(2020, 07, 13, 0, 0, 0);
var te = new DateTime(2020, 07, 13, 23, 59, 59);
var totTime = new TimeSpan();
for (ushort i = 1; i <= 50; i++)
{
var tc = a.GetTechCycle(ts, te, i);
var ad = a.GetAnalogDiscret(ts, te, i);
Console.WriteLine("VDP " + i.ToString("D2"));
var totalVdpTime = new TimeSpan();
foreach (var e in tc)
{
int[] chk1 = {
(int)TechCycle.Operation.cooling_ingot,
(int)TechCycle.Operation.cooling_reflow,
(int)TechCycle.Operation.cooling_welding };
int[] chk2 =
{
(int)TechCycle.Operation.end_tech_cycle,
(int)TechCycle.Operation.unloading_loading,
(int)TechCycle.Operation.looking_welding,
(int)TechCycle.Operation.unloading_kit
};
if (!chk1.Contains((int)e.index) && !chk2.Contains((int)e.index))
continue;
if (chk1.Contains((int)e.index))
{
var test =
(from l in ad.an[13]
where l.Item1 >= e.start &&
l.Item1 <= e.end &&
l.Item2 >= 30
select l).ToArray();
if (test.Length == 0)
continue;
}
Tuple<DateTime, bool?> currstat = new Tuple<DateTime, bool?>(e.start, null);
foreach (var d in ad.di[22])
{
if (
currstat.Item1 <= e.end &&
d.Item1 >= e.start &&
currstat.Item2.HasValue &&
currstat.Item2.Value
)
{
var t1 = currstat.Item1 > e.start ? currstat.Item1 : e.start;
var t2 = d.Item1 > e.end ? e.end : d.Item1;
var res = t2 - t1;
Console.Write(e.start.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t');
Console.Write(Names.techCycle[(int)e.index] + '\t');
Console.WriteLine(res.ToString(@"hh\:mm\:ss"));
totalVdpTime = totalVdpTime.Add(res);
}
currstat = d;
}
}
Console.WriteLine("Total VDP Time: " + totalVdpTime.ToString(@"hh\:mm\:ss"));
totTime = totTime.Add(totalVdpTime);
}
Console.WriteLine("Total Time: " + totTime.ToString(@"hh\:mm\:ss"));
Console.ReadKey();
}
static void test5()
{
var a = new STPClient();
var i = DateTime.Now.AddDays(-1 * new Random().Next(10));
Console.WriteLine(i.ToString());
var b = a.GetListPasport(i);
foreach (var e in b)
Console.WriteLine(e.Item1 + '\t' + e.Item2);
Console.WriteLine();
var r = new Random().Next(b.Length);
Console.WriteLine(b[r].Item1 + '\t' + b[r].Item2);
var p = a.GetPasport(b[r].Item2);
Console.WriteLine(p.ToString());
}
static void test6()
{
var a = new STPClient();
var s = DateTime.Now.AddDays(-30);
var e = DateTime.Now.AddDays(-20);
var b = a.GetIshData(s, e, 37);
Console.WriteLine(s.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + e.ToString(@"yyyy.MM.dd HH:mm:ss.ff"));
foreach(var t in b)
{
Console.WriteLine(t.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + t.id.ToString("D2") + '\t' + t.value);
}
}
static void test7()
{
var w = new STPClient();
var s = new DateTime(2020, 06, 1);
var e = new DateTime(2020, 07, 22);
var r1 = new List<Tuple<string, string>>();
var r2 = new List<Pasport>();
for (var i = s; i < e; i = i.AddDays(1))
{
var a = w.GetListPasport(i);
foreach(var b in a)
{
var c = w.GetPasport(b.Item2);
var d = w.GetIshData(c.time_start, c.time_end, c.numVDP);
var flag = false;
foreach(var f in d)
{
if (f.id != 0) continue;
//Console.Write(f.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + b.Item1 + '\t' + f.value);
Regex r = new Regex(@"(\w*)-(\w{3})-32-031(\w*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
//Console.WriteLine('\t' + r.IsMatch(f.value).ToString());
flag = flag || r.IsMatch(f.value);
}
if (flag)
{
r1.Add(b); r2.Add(c);
Console.WriteLine(b.Item1 + '\t' +
c.time_start.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' +
c.time_end.ToString(@"yyyy.MM.dd HH:mm:ss.ff"));
foreach (var f in d)
{
if (f.id != 0) continue;
Console.WriteLine(f.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + f.value);
}
}
}
}
Console.WriteLine();
var fs = new StreamWriter(Directory.GetCurrentDirectory() + '\\' + "result.txt");
for(var i = 0; i < r1.Count; i++)
{
var a = w.GetProtectData(r2[i].time_start, r2[i].time_end, r2[i].numVDP);
var b = new List<Protect>();
foreach(var c in a)
if (c.id == 72) b.Add(c);
if (b.Count > 0)
{
Console.WriteLine(r1[i].Item1 + '\t' +
r2[i].time_start.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' +
r2[i].time_end.ToString(@"yyyy.MM.dd HH:mm:ss.ff"));
fs.WriteLine(r1[i].Item1 + '\t' +
r2[i].time_start.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' +
r2[i].time_end.ToString(@"yyyy.MM.dd HH:mm:ss.ff"));
foreach (var d in b)
{
Console.WriteLine(d.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + d.id.ToString("D2") + '\t' + d.value);
fs.WriteLine(d.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + '\t' + d.value);
}
}
}
fs.Close();
}
2020-09-29 08:18:25 +05:00
static void test8()
{
var w = new STPClient();
var s = new DateTime(2020, 09, 30);
var e = new DateTime(2020, 10, 03);
//var vdps = new int[] { 2, 3, 4, 10, 11, 12, 16, 21, 22, 23, 27, 31, 33, 36, 45 };
var vdps = new int[] { 3, 4, 21, 36 };
2020-09-29 08:18:25 +05:00
foreach (var vdp in vdps)
{
var a = w.GetProtectData(s, e, (ushort)vdp);
a = a.FindAll(x => x.id == 35 || x.id == 70 || x.id == 71);
Console.WriteLine("VDP " + vdp.ToString("D2"));
2020-09-29 08:18:25 +05:00
foreach (var b in a)
{
Console.Write(b.id.ToString("D2") + " ");
2020-09-29 08:18:25 +05:00
Console.Write(b.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff"));
Console.WriteLine(" " + b.value.ToString("D2"));
}
var fs = new StreamWriter(Directory.GetCurrentDirectory() + '\\' + vdp.ToString("D2") + ".txt");
fs.WriteLine("35 - Отсутствует связь с контроллером ГМП");
fs.WriteLine("70 - Смещение начала архивации");
fs.WriteLine("70 - Смещение конца архивации");
fs.WriteLine();
fs.WriteLine("№ защиты \t Дата возникновения записи \t Состояние");
2020-09-29 08:18:25 +05:00
foreach (var b in a)
fs.WriteLine(b.id.ToString("D2") + "\t" + b.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + "\t" + b.value.ToString("D2"));
2020-09-29 08:18:25 +05:00
fs.Close();
}
}
static void test9()
{
var w = new STPClient();
var s = new DateTime(2020, 10, 05);
var e = new DateTime(2020, 10, 07);
2020-09-29 08:18:25 +05:00
var vdp = 1;
var a = w.GetProtectData(s, e, (ushort)vdp);
/*var res = new List<int>();
foreach (var b in a)
if (!res.Contains(b.id))
res.Add(b.id);
res.Sort((x, y) => x.CompareTo(y));*/
foreach (var b in a)
Console.WriteLine(b.id.ToString("D3") + " " + b.time.ToString(@"yyyy.MM.dd HH:mm:ss.ff") + " " + b.value);
}
2020-11-19 16:30:38 +05:00
static void test10()
{
var a = new List<List<SZOWork>>();
a.Add(new List<SZOWork>());
var tc = new TechCycle()
{
index = TechCycle.Operation.unloading_loading,
start = DateTime.Now.AddHours(-2),
end = DateTime.Now
};
var b = new SZOWork()
{
tc = tc,
tStart = DateTime.Now.AddHours(-2),
tEnd = DateTime.Now.AddHours(-1.3)
};
a[0].Add(b);
b= new SZOWork()
{
tc = tc,
tStart = DateTime.Now.AddHours(-1.3),
tEnd = DateTime.Now.AddHours(-0.7)
};
a[0].Add(b);
b = new SZOWork()
{
tc = tc,
tStart = DateTime.Now.AddHours(-0.7),
tEnd = DateTime.Now.AddHours(-0.2)
};
a[0].Add(b);
CreatePDF.PDFSZO(a, DateTime.Now);
}
static void test11()
{
var tStart = new DateTime(2020, 11, 17, 0, 0, 0);
var tEnd = new DateTime(2020, 11, 17, 23, 59, 59, 999);
var r = new List<List<SZOWork>>();
for (var i = 1; i <= 50; i++)
r.Add(CollectData.GetSZOWorks(tStart, tEnd, (ushort)i));
CreatePDF.PDFSZO(r, tStart);
}
2020-09-04 12:49:15 +05:00
}
}