Stat.CreateOrUpdateAVGAndSD C# (CSharp) Méthode

CreateOrUpdateAVGAndSD() public méthode

public CreateOrUpdateAVGAndSD ( ) : void
Résultat void
    public void CreateOrUpdateAVGAndSD()
    {
        if( ! makeAVGSD)
            return;

        //delete the AVG, SD rows of store if we are not in report
        try {
            Gtk.TreeIter iter;
            bool okIter = store.GetIterFirst(out iter);
            if(okIter) {
                do {
                    if(! isNotAVGOrSD(iter)) {
                        //delete AVG and SD rows
                        okIter = store.Remove(ref iter);
                        okIter = store.Remove(ref iter);
                        //okIter is because iter is invalidated when deleted last row
                    }
                } while (okIter && store.IterNext(ref iter));
            }
        } catch {
            LogB.Error("On graph or report (or graph, report)");
        }

        //if multisession number of dataCols will be sessions
        //else it will be dataColumns
        int myDataColumns = 0;
        if(sessions.Count > 1)
            myDataColumns = sessions.Count;
        else
            myDataColumns = dataColumns;

        //if called from a graph will not work because
        //nothing is in store
        try {
            if(statPrintedData.Count > 0) {
                double [] sumValue = new double [myDataColumns];
                string [] valuesList = new string [myDataColumns];
                int [] valuesOk = new int [myDataColumns]; //values in a checked row and that contain data (not "-")
                //initialize values
                for(int j=1; j< myDataColumns ; j++) {
                    sumValue[j] = 0;
                    valuesList[j] = "";
                    valuesOk[j] = 0;
                }
                int rowsFound = 0;
                int rowsProcessed = 0;
                foreach(string myStatData in statPrintedData) {
                    string [] myStrFull = myStatData.Split(new char[] {':'});

                        if(isThisRowMarked(rowsFound)) {
                            for(int column = 0; column < myDataColumns; column ++) {
                                //LogB.Information("value: {0}", store.GetValue(iter, column+2));
                                //string myValue = store.GetValue(iter, column+2).ToString();
                                string myValue = myStrFull[column+1];
                                if(myValue != "-") {
                                    if(valuesOk[column] == 0)
                                        valuesList[column] = myValue;
                                    else
                                        valuesList[column] += ":" + myValue;
                                    sumValue[column] += Convert.ToDouble(myValue);
                                    valuesOk[column] ++;
                                }
                            }
                            rowsProcessed ++;
                        }
                    rowsFound ++;
                }

                if(rowsProcessed > 0) {
                    string [] sendAVG = new string [myDataColumns +1];
                    string [] sendSD = new string [myDataColumns +1];

                    sendAVG[0] = Catalog.GetString("AVG");
                    sendSD[0] =  Catalog.GetString("SD");

                    for (int j=0; j < myDataColumns; j++) {
                        if(valuesOk[j] > 0)
                            sendAVG[j+1] = Util.TrimDecimals( (sumValue[j] / valuesOk[j]).ToString(), pDN );
                        else
                            sendAVG[j+1] = "-";
                        //LogB.Information("j({0}), SendAVG[j]({1}), valuesList[j]({2})", j, sendAVG[j+1], valuesList[j]);
                        sendSD[j+1] = Util.TrimDecimals( Util.CalculateSD(valuesList[j], sumValue[j], valuesOk[j]).ToString(), pDN );
                        //LogB.Information("j({0}), SendSD[j]({1})", j, sendSD[j+1]);
                    }
                    printData( sendAVG );
                    printData( sendSD );
                }
            }
        } catch {
            /* check this if it's needed now*/
            //write a row of AVG because graphs of stats with AVG and SD
            //are waiting the AVG row for ending and painting graph
            LogB.Error("catched!");
            string [] sendAVG = new string [myDataColumns +1];
            sendAVG[0] = Catalog.GetString("AVG");
            printData(sendAVG);
            LogB.Information("Graph should work!");
        }
    }

Usage Example

Exemple #1
0
 public void CreateOrUpdateAVGAndSD()
 {
     myStat.CreateOrUpdateAVGAndSD();
 }