/// 保存打印记录
        /// </summary>
        /// <param name="print"></param>
        public JsonModel SavePrintData(string Data)
        {
            DBDeliverJSPrint dbs   = new DBDeliverJSPrint();
            printData        print = Newtonsoft.Json.JsonConvert.DeserializeObject <printData>(Data);
            JsonModel        model = new JsonModel();

            MDSelfServiceMachine.MDDeliverJSPrint modelPlan = new MDSelfServiceMachine.MDDeliverJSPrint();
            try
            {
                modelPlan.StrPlanGUID     = print.data.strPlanGUID;
                modelPlan.StrSiteGUID     = print.data.cid;
                modelPlan.StrTrainmanGUID = print.data.strTrainmanGUID;
                string   strPrintTime = print.data.dtPrintTime;
                DateTime dtPrint;
                if (DateTime.TryParse(strPrintTime, out dtPrint))
                {
                    modelPlan.dtPrintTime = dtPrint;
                }
                dbs.AddDeliverJSPrint(modelPlan);
            }
            catch (Exception ex)
            {
                TF.CommonUtility.LogClass.logex(ex, "");
                model.result    = "1";
                model.returnStr = "提交失败:" + ex.Message;
            }
            return(model);
        }
Esempio n. 2
0
        public string RecordUpload(string input, string cid)
        {
            Upload_Out model = new Upload_Out();
            {
                Newtonsoft.Json.Converters.JsonVirtualConverter <jsBase> jvc = new Newtonsoft.Json.Converters.JsonVirtualConverter <jsBase>("stepID", t =>
                {
                    switch (t)
                    {
                    case "1004":
                        return(new Reading());

                    case "1012":
                        return(new printData());

                    default:
                        return(null);
                    }
                });
                List <jsBase> array = Newtonsoft.Json.JsonConvert.DeserializeObject <List <jsBase> >(input, jvc);
                TF.RunSafty.Model.TAB_ReadHistory read = new TF.RunSafty.Model.TAB_ReadHistory();
                try
                {
                    if (array != null)
                    {
                        foreach (jsBase t in array)
                        {
                            if (t is Reading)
                            {
                                Reading reading = (Reading)t;
                                SaveReadings(reading.data, cid);
                            }
                            else if (t is printData)
                            {
                                printData print = (printData)t;
                                SavePrintData(print.data, cid);
                            }
                        }
                    }
                    model.result    = "0";
                    model.returnStr = "提交成功";
                }
                catch (Exception ex)
                {
                    TF.CommonUtility.LogClass.logex(ex, "");
                    model.result    = "1";
                    model.returnStr = "提交失败:" + ex.Message;
                }
                string result = Newtonsoft.Json.JsonConvert.SerializeObject(model);
                return(result);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This function calculates the accuracy of the labeling.
        /// Note: For the sake of a good running time we assume that the dataCheck and
        /// dataFiles contain corresponding files i.e. dataCheck[i] corresponds to
        /// dataFiles[i].
        /// </summary>
        public void calcAccuracy(string logFile)
        {
            //string dummyFile = "foo.txt";
            StreamWriter swr = null;//new StreamWriter(dummyFile);
            printData    printAcc;

            if (logFile.Length != 0)
            {
                swr      = new StreamWriter(logFile);
                printAcc = new printData(swr.WriteLine);
            }
            else
            {
                printAcc = new printData(Console.WriteLine);
            }


            /* at index 0 -> data for wires
             * at index 1 -> data for gates
             * at index 2 -> data for labels
             */
            double[] numCorrectOverall = new double[3];
            double[] numTotalOverall   = new double[3];
            double   totalLabels       = 0.0;
            double   mislabeledAsOther = 0.0;
            double   mislabeledAsWire  = 0.0;
            double   mislabeledAsGate  = 0.0;
            double   correctLabels     = 0.0;
            double   totalSubstrokes   = 0.0;
            double   missedSubstrokes  = 0.0;
            double   unknownLabels     = 0.0;

            List <float?> probCorWires   = new List <float?>();
            List <float?> probWrongWires = new List <float?>();

            List <float?> probCorGates   = new List <float?>();
            List <float?> probWrongGates = new List <float?>();

            List <float?> probCorLabels   = new List <float?>();
            List <float?> probWrongLabels = new List <float?>();

            //Check whether we are comparing the same substrokes.
            //Check for the sizes.
            for (int index = 0; index < dataLabeled.Count; ++index)
            {
                string fileLabeled = (string)dataLabeled[index];
                string fileCheck   = (string)dataCheck[index];

                //printAcc("fileLabeled: {0}", fileLabeled);
                //printAcc("fileCheck: {0}", fileCheck);

                Sketch.Sketch sketchLabeled = (new ReadXML(fileLabeled)).Sketch;
                Sketch.Sketch sketchCheck   = (new ReadXML(fileCheck)).Sketch;

                Fragment.fragmentSketch(sketchLabeled);
                Fragment.fragmentSketch(sketchCheck);

                /* at index 0 -> data for wires
                 * at index 1 -> data for gates
                 * at index 2 -> data for labels
                 */
                double[] numCorrect = new double[3];
                double[] numTotal   = new double[3];

                totalSubstrokes += sketchLabeled.Substrokes.Length;
                //Check whether we are comparing the same substrokes.
                //Check for the sizes.
                for (int i = 0; i < sketchLabeled.Substrokes.Length; ++i)
                {
                    Sketch.Substroke subStr       = sketchLabeled.Substrokes[i];
                    string           labelCorrect = subStr.GetFirstLabel();
                    //
                    //if (labelCorrect.Equals("Wire") || labelCorrect.Equals("Label"))
                    //    labelCorrect = "Nongate";
                    string labelCorrectId = subStr.XmlAttrs.Id.ToString();

                    float xCorrect = subStr.XmlAttrs.X.Value;
                    float yCorrect = subStr.XmlAttrs.Y.Value;

                    //string labelCorrect = subStr.ParentStroke.XmlAttrs.Type.ToString();
                    //string labelCorrectId = subStr.ParentStroke.XmlAttrs.Id.ToString();

                    if (labelCorrect.Length == 0 || labelCorrect.Equals("BUBBLE"))
                    {
                        printAcc("*** Skipping the following id: {0}***", labelCorrectId);
                        continue;
                    }


                    string labelCheck   = "";
                    string labelCheckId = "";

                    float xCheck = -1;
                    float yCheck = -1;

                    float?prob = 0;

                    foreach (Sketch.Substroke sub in sketchCheck.Substrokes)
                    {
                        string tmp  = sub.XmlAttrs.Id.ToString();
                        float  xTmp = sub.XmlAttrs.X.Value;
                        float  yTmp = sub.XmlAttrs.Y.Value;

                        //if (tmp.Equals(labelCorrectId))
                        if (xTmp == xCorrect && yTmp == yCorrect)
                        {
                            labelCheck   = sub.GetFirstLabel();
                            labelCheckId = sub.XmlAttrs.Id.ToString();

                            xCheck = sub.XmlAttrs.X.Value;
                            yCheck = sub.XmlAttrs.Y.Value;

                            //prob = sub.ParentShapes[0].XmlAttrs.Probability.Value;
                            break;
                        }
                    }

                    if (xCheck == -1 || yCheck == -1)
                    {
                        printAcc("*** A stroke is not found in sketchCheck ***");
                        continue;
                    }

                    /*
                     * if (labelCheck.Length == 0)
                     * {
                     *
                     *  printAcc("*** LabelCheck has length 0 => could not find a sustroke in sketchCheck ***");
                     *  printAcc("Correct label: {0} labelCorrectId: {1}", labelCorrect, labelCorrectId);
                     ++missedSubstrokes;
                     *  continue;
                     * }
                     */
                    //printAcc("");
                    //printAcc("LabelCorrectId is: {0}", labelCorrectId);
                    //printAcc("LabelCheckId is  : {0}", labelCheckId);
                    //printAcc("Type of label is : {0}", labelCheck);
                    //printAcc("Probability for this label is: {0}", prob);

                    switch (labelCorrect)
                    {
                    case "Wire":
                        ++totalLabels;
                        ++(numTotal[0]);
                        ++(numTotalOverall[0]);
                        if (labelCheck.Equals("Wire"))
                        {
                            ++correctLabels;
                            ++(numCorrect[0]);
                            ++(numCorrectOverall[0]);

                            probCorWires.Add(prob);
                        }
                        else
                        {
                            probWrongWires.Add(prob);
                        }

                        break;

                    case "Gate":
                        ++totalLabels;
                        ++(numTotal[1]);
                        ++(numTotalOverall[1]);
                        if (labelCheck.Equals("Gate"))
                        {
                            ++correctLabels;
                            ++(numCorrect[1]);
                            ++(numCorrectOverall[1]);

                            probCorGates.Add(prob);
                        }
                        else
                        {
                            probWrongGates.Add(prob);
                        }
                        break;

                    case "Label":
                        ++totalLabels;
                        ++(numTotal[2]);
                        ++(numTotalOverall[2]);

                        if (labelCheck.Equals("Wire"))
                        {
                            ++mislabeledAsWire;
                            ++mislabeledAsOther;
                        }
                        if (labelCheck.Equals("Gate"))
                        {
                            ++mislabeledAsGate;
                            ++mislabeledAsOther;
                        }

                        if (labelCheck.Equals("Label"))
                        {
                            ++correctLabels;
                            ++(numCorrect[2]);
                            ++(numCorrectOverall[2]);

                            probCorLabels.Add(prob);
                        }
                        else
                        {
                            probWrongLabels.Add(prob);
                        }
                        break;

                    /*//---Start new part.
                     * case "Gate":
                     ++(numTotal[0]);
                     ++(numTotalOverall[0]);
                     *  if (labelCheck.Equals("Gate"))
                     *  {
                     ++(numCorrect[0]);
                     ++(numCorrectOverall[0]);
                     *  }
                     *  break;
                     *
                     * case "Nongate":
                     ++(numTotal[1]);
                     ++(numTotalOverall[1]);
                     *  if (labelCheck.Equals("Nongate"))
                     *  {
                     ++(numCorrect[1]);
                     ++(numCorrectOverall[1]);
                     *  }
                     *  break;
                     */ //---End

                    default:
                        printAcc("*** UNKNOWN LABEL: Correct label: {0}, Examined label: {1}", labelCorrect, labelCheck);
                        printAcc("***                Correct id: {0}", labelCorrectId);
                        ++unknownLabels;
                        break;
                    }
                }

                printAcc("");
                printAcc("Comparing files {0} and {1}.", fileCheck, fileLabeled);
                printAcc("Percentage of correctly labeled Wires:  {0:##.000%}",
                         numCorrect[0] / numTotal[0]);
                printAcc("Percentage of correctly labeled Gates:  {0:##.000%}",
                         numCorrect[1] / numTotal[1]);
                printAcc("Percentage of correctly labeled Labels: {0:##.000%}",
                         numCorrect[2] / numTotal[2]);

                /*//---Start new part.
                 * printAcc("");
                 * printAcc("Comparing files {0} and {1}.", fileCheck, fileLabeled);
                 * printAcc("Percentage of correctly labeled Gate:  {0:##.000%}",
                 *  numCorrect[0] / numTotal[0]);
                 * printAcc("Percentage of correctly labeled Nongate:  {0:##.000%}",
                 *  numCorrect[1] / numTotal[1]);
                 * //---End of new part.*/
            }

            printAcc("");
            printAcc("Results based on whole set of data:");
            printAcc("Labels missed: {0} out of {1} => {2:##.000%}",
                     missedSubstrokes, totalSubstrokes, missedSubstrokes / totalSubstrokes);
            printAcc("Unlabeled strokes: {0} out of {1} => {2:##.000%}",
                     unknownLabels, totalLabels, unknownLabels / totalLabels);
            printAcc("Overall accuracy: {0:##.000%}",
                     correctLabels / totalLabels);
            printAcc("Percentage of correctly labeled Wires: {0:##.000%}",
                     numCorrectOverall[0] / numTotalOverall[0]);
            printAcc("Percentage of correctly labeled Gates: {0:##.000%}",
                     numCorrectOverall[1] / numTotalOverall[1]);
            printAcc("Percentage of correctly labeled Labels: {0:##.000%}",
                     numCorrectOverall[2] / numTotalOverall[2]);
            printAcc("Percentage of labels mislabeled as Wires: {0:##.000%}",
                     mislabeledAsWire / mislabeledAsOther);
            printAcc("Percentage of labels mislabeled as Gates: {0:##.000%}",
                     mislabeledAsGate / mislabeledAsOther);

            /*//---Start new part.
             * printAcc("");
             * printAcc("Results based on whole set of data:");
             * printAcc("Percentage of correctly labeled Gates: {0:##.000%}",
             *  numCorrectOverall[0] / numTotalOverall[0]);
             * printAcc("Percentage of correctly labeled Nongates: {0:##.000%}",
             *  numCorrectOverall[1] / numTotalOverall[1]);
             * //---End new part.*/

            if (logFile.Length != 0)
            {
                swr.Close();
            }

            /*
             * swr1.Close(); swr2.Close(); swr3.Close();
             * swr4.Close(); swr5.Close(); swr6.Close();
             */
        }
Esempio n. 4
0
        public void calcStats(string criterion, string logFile)
        {
            //string dummyFile = "foo.txt";
            StreamWriter sw = null;//new StreamWriter(dummyFile);
            printData    print;

            if (logFile.Length != 0)
            {
                sw    = new StreamWriter(logFile);
                print = new printData(sw.WriteLine);
            }
            else
            {
                print = new printData(Console.WriteLine);
            }

            List <double> overallDataGate  = new List <double>();
            List <double> overallDataWire  = new List <double>();
            List <double> overallDataLabel = new List <double>();
            List <double> overallDataAll   = new List <double>();

            foreach (string filename in dataFiles)
            {
                //Console.WriteLine("Filename: {0}", filename);
                //Console.WriteLine("Length: {0}", dataFiles.Count);

                FeatureStroke featStr;
                string        strokeLabel;
                double        data = 0;

                Sketch.Sketch sketchHolder = (new ReadXML(filename)).Sketch;
                switchToWireGateLabel(ref sketchHolder);
                Stroke[] sketchStrokes = sketchHolder.Strokes;

                List <double> dataGate  = new List <double>();
                List <double> dataWire  = new List <double>();
                List <double> dataLabel = new List <double>();
                List <double> dataAll   = new List <double>();

                foreach (Sketch.Substroke subStroke in sketchHolder.Substrokes)
                {
                    featStr     = new FeatureStroke(subStroke);
                    strokeLabel = subStroke.GetFirstLabel();
                    calcData(ref data, featStr, criterion);

                    //Console.WriteLine("SubStroke Label: {0}", strokeLabel);
                    //Console.WriteLine("Circular Ink Density: {0}", data);
                    //Console.WriteLine("");

                    if (strokeLabel.Equals("Wire"))
                    {
                        dataWire.Add(data);
                        overallDataWire.Add(data);
                        dataAll.Add(data);
                        overallDataAll.Add(data);
                    }
                    else if (strokeLabel.Equals("Gate"))
                    {
                        dataGate.Add(data);
                        overallDataGate.Add(data);
                        dataAll.Add(data);
                        overallDataAll.Add(data);
                    }
                    else if (strokeLabel.Equals("Label"))
                    {
                        dataLabel.Add(data);
                        overallDataLabel.Add(data);
                        dataAll.Add(data);
                        overallDataAll.Add(data);
                    }
                    else
                    {
                        print("ERROR: Unknown label of a stroke.");
                    }
                }

                print("");
                print("Filename: {0}", filename);
                double[]   gateArray = dataGate.ToArray();
                statistics gateStats = new statistics(gateArray);
                print("Gates -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                      gateStats.mean(), gateStats.s(), gateStats.max(), gateStats.min());

                double[]   wireArray = dataWire.ToArray();
                statistics wireStats = new statistics(wireArray);
                print("Wire  -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                      wireStats.mean(), wireStats.s(), wireStats.max(), wireStats.min());

                double[]   labelArray = dataLabel.ToArray();
                statistics labelStats = new statistics(labelArray);
                print("Label -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                      labelStats.mean(), labelStats.s(), labelStats.max(), labelStats.min());

                double[]   allArray = dataAll.ToArray();
                statistics allStats = new statistics(allArray);
                print("Total -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                      allStats.mean(), allStats.s(), allStats.max(), allStats.min());
            }

            print("");
            print("Calculations based on data from all the files");
            double[]   overallGateArray = overallDataGate.ToArray();
            statistics overallGateStats = new statistics(overallGateArray);

            print("Gates -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                  overallGateStats.mean(), overallGateStats.s(), overallGateStats.max(), overallGateStats.min());

            double[]   overallWireArray = overallDataWire.ToArray();
            statistics overallWireStats = new statistics(overallWireArray);

            print("Wire  -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                  overallWireStats.mean(), overallWireStats.s(), overallWireStats.max(), overallWireStats.min());

            double[]   overallLabelArray = overallDataLabel.ToArray();
            statistics overallLabelStats = new statistics(overallLabelArray);

            print("Label -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                  overallLabelStats.mean(), overallLabelStats.s(), overallLabelStats.max(), overallLabelStats.min());

            double[]   overallArray = overallDataAll.ToArray();
            statistics overallStats = new statistics(overallArray);

            print("Total -> Mean: {0:###.000}, StDev: {1:###.000}, Max: {2:###.000}, Min: {3:###.000}",
                  overallStats.mean(), overallStats.s(), overallStats.max(), overallStats.min());


            if (logFile.Length != 0)
            {
                sw.Close();
            }
        }