示例#1
0
 public Box(DataScan data)
 {
     products      = new List <Product>();
     Scanner       = data.Scanner;
     Barcode       = data.Barcode;
     BoxCreateTime = data.CreateDateTime;
 }
示例#2
0
            internal async Task <DataScan> ProcessNumericData(Dictionary <string, string> data)
            {
                DataScan result = new DataScan()
                {
                    values     = new Dictionary <string, float>(),
                    errorcount = 0,
                    nullcount  = 0
                };
                await Task.Run(() => {
                    foreach (var item in data)
                    {
                        System.Text.RegularExpressions.Match match = Utils.RegularExpressions.Numbers.Match(item.Value);
                        if (match.Success)
                        {
                            if (float.Parse(match.Value) == 0)
                            {
                                result.nullcount++; continue;
                            }
                            result.values.Add(item.Key, float.Parse(match.Groups[0].Value));
                        }
                        else
                        {
                            Core.ErrorLog.Log("Error during Rexex Match of Scan() data for user " + item.Key, true);
                            result.errorcount++;
                        }
                    }
                });

                return(result);
            }
示例#3
0
 //Mode: -Test -Work
 //Action:  -Box -Product
 public static void Analize(DataScan data)
 {
     if (data.ScannerAction == (int)ScannerAction.BoxScan)
     {
         //newBox or delete Box
     }
     if (data.ScannerAction == (int)ScannerAction.ProductScan)
     {
         //addProduct or getProduct
     }
 }
示例#4
0
 public DataScannedEvent(DateTime timestamp, DataScan datalinktype) : base(timestamp, NAME)
 {
     this.datalinktype = datalinktype.name;
 }
示例#5
0
        public void TestDataScanFromEDName()
        {
            DataScan dataScan = DataScan.FromEDName("$Datascan_DataPoint;");

            Assert.AreEqual("Data Point", dataScan.invariantName);
        }
示例#6
0
 ////Events
 public void ScanEvent(DataScan dataScan)
 {
     Analyzer.Analize(dataScan);
 }
示例#7
0
            public async override void PluginMethod(Message m)
            {
                bool modeAnonymous = m.Args.Contains("-a") ? true : false;                 //Are max and min named? Requires modeStatistic
                bool modeStatistic = m.Args.Contains("-s") ? true : false;
                bool modeGreater   = m.Args.Contains("-gt") ? true : false;
                bool modeLesser    = m.Args.Contains("-lt") ? true : false;

                m.Args = m.Args.Where(n => n != "-a").ToArray();
                m.Args = m.Args.Where(n => n != "-s").ToArray();

                float cutoffValue = 0f;

                if (modeGreater && modeLesser)
                {
                    m.Reply("Cannot scan for both GreaterThan and LesserThan. Decide."); return;
                }
                if (modeAnonymous && !modeStatistic)
                {
                    m.Reply("Deactivating mode anonymous is only supported with mode statistic."); return;
                }
                if ((modeLesser || modeGreater) && !modeStatistic)
                {
                    modeStatistic = true;
                }
                if (modeLesser || modeGreater)
                {
                    int cutoffPos = Array.IndexOf(m.Args, modeLesser ? "-lt" : "-gt");
                    if (cutoffPos >= 0)
                    {
                        cutoffValue = float.Parse(m.Args[cutoffPos + 1]);
                        m.Args      = m.Args.Take(Math.Max(cutoffPos - 1, 0)).Concat(m.Args.Skip(cutoffPos + 1)).ToArray();                    //Danger Will Robinson! why not just... idk, look for recognised args and make 'em a list or something? Switch statement.
                    }
                }

                List <User> dataPool             = m.sourceChannel.Users.ToList();
                Dictionary <string, string> data = new Dictionary <string, string>(dataPool.Count);
                string results;

                Console.WriteLine("Preparing to execute Task Pool...");
                Task  DataScan = Task.WhenAll(dataPool.Select(n => n.GetBasicProfileInfo()));
                await DataScan;

                Console.WriteLine("Awaited Task Pool.");
                data = dataPool.ToDictionary(x => x.Name, x => x.TryGetData(m.Body));

                if (modeStatistic)                   //transform all to numeric
                {
                    DataScan numData = await ProcessNumericData(data);

                    if (numData.values.Count == 0)
                    {
                        m.Reply("Could not find/parse any numeric data for input '" + m.Body + "'."); return;
                    }
                    //TODO Instead of simpled regex, then float.parse, do utils.math.measurementFromNumber if you ever code it. (As if).
                    if (modeLesser || modeGreater)
                    {
                        int fullCount   = numData.values.Count;
                        int lesserCount = numData.values.Values.Where(x => x <= cutoffValue).Count();
                        results = string.Format(CultureInfo.InvariantCulture, "Comparative analysis complete. {0:0} of {1:0} users successfully parsed for '{2}'. {3} users had no value set, {4} failed parsing.\n{5:0} users have values {6} specified threshold of {7:0.0}.", fullCount, dataPool.Count, m.Body, numData.nullcount, numData.errorcount, modeLesser ? lesserCount : fullCount - lesserCount, modeLesser ? "below" : "above", cutoffValue);
                    }
                    else
                    {
                        float mean = numData.values.Values.Average();
                        //double? median = Utils.Math.Median(numData.Keys);
                        float  _min  = numData.values.Values.Min();
                        string min   = modeAnonymous ? _min.ToString("0.0", CultureInfo.InvariantCulture) + " [" + string.Join(", ", numData.values.Where(n => n.Value == _min).Select(n => n.Key)).TrimEnd(new char[] { ' ', ',' }) + "]" : _min.ToString("0.0", CultureInfo.InvariantCulture);
                        float  _max  = numData.values.Values.Max();
                        string max   = modeAnonymous ? _max.ToString("0.0", CultureInfo.InvariantCulture) + " [" + string.Join(", ", numData.values.Where(n => n.Value == _max).Select(n => n.Key)).TrimEnd(new char[] { ' ', ',' }) + "]" : _max.ToString("0.0", CultureInfo.InvariantCulture);
                        double stDev = Utils.Math.StDev(numData.values.Values);
                        results = string.Format(CultureInfo.InvariantCulture, "Statistical analysis complete. {0:0} of {1:0} users successfully parsed for '{2}'. {3} users had no value set, {4} failed parsing.\nMin: {5:0.0}. Max: {6:0.0}. Average: {7:0.0}. Standard deviation: {8:0.0}", numData.values.Count, dataPool.Count, m.Body, numData.nullcount, numData.errorcount, min, max, mean, stDev);
                    }
                }
                else                    //Histogram-type analysis, ~10 most frequent
                {
                    int nullCount = data.Values.Where(x => x != "Not set").Count();
                    Utils.Collections.Counter <string> DataTypes = new Utils.Collections.Counter <string>(data.Values.Where(x => x != "Not set"));
                    results = string.Format(CultureInfo.InvariantCulture, "Quantitative analysis of {0} users for '{1}' complete. {2} users had no value set. {3} unique categories found, displaying a maximum of 10:\n{4}", dataPool.Count, m.Body, nullCount, DataTypes.Count, DataTypes.ToString(10));
                }
                //foreach (User u in dataPool) { u.Dispose(); }
                m.Reply(results, IO.ReplyMode.AsOriginal);
            }