示例#1
0
        internal SliceDataResults QuerySliceData(string direction, string sliceType,  SliceData aSlice, List<int> variableColumnsToCalculate, int sliceNum, float domainToQuery, bool weightByVol, bool weightByTonnes, int domainColumnID, bool weightByLength)
        {
            SliceDataResults sres = new SliceDataResults();
            
            // pick out all records for the slice
            
            // get the variable columns
            int numCols = variableColumnsToCalculate.Count;
            sres.Initialise(numCols,sliceNum);
            Object[] cols = new Object[numCols];

            for (int i = 0; i < numCols; i++) {
                cols[i] = columnData[variableColumnsToCalculate[i]];
            }

            List<int> sliceRowIDs = aSlice.rowIDList;
            
            sres.sliceCentrePoint = aSlice.sliceCentre;
            
            
         


                    for (int col = 0; col < numCols; col++)
                    {

                        DataColumn<float> varColumn = (DataColumn<float>)cols[col];
                        double tot = 0;
                        double totVol = 0;
                        double totVolAdjustedWt = 0;
                        int dataRecords = 0;
                        
                        double tonnes = 0;
                        foreach (int zz in sliceRowIDs)
                        {
                            int domain = 0;
                            domain = GetDomainForRow(zz, domainColumnID);
                            double ff = varColumn.GetRecordAt(zz);
                            if (ff != columnNullVal && domain == domainToQuery)
                            {

                                float weighting = 1;
                                if (weightByVol == true && weightByTonnes == false)
                                {
                                    weighting = GetVolumeForRow(zz);

                                }
                                else if (weightByVol == true && weightByTonnes == true)
                                {
                                    weighting = GetTonnesForRow(zz);
                                }
                                else
                                {
                                    // no weighting for composites
                                    weighting = 1.0f;
                                    if (weightByLength) {
                                        GetWeightForRow(zz);
                                    }
                                }

                                tot += ff;
                                dataRecords++;
                                double vaw = weighting * ff;
                                totVolAdjustedWt += vaw;
                                totVol += weighting;
                                if (weightByTonnes)
                                {
                                    tonnes += GetTonnesForRow(zz);
                                }

                                // write the data to a datafile
                               // string dtLine = "";
                               // dtLine =  ff + ", " + weighting;
                               // dtLine = GetDebugDataPrintout(zz) + ", Val, " + ff + " , Vol, " + weighting;
                             //   sw.WriteLine(dtLine);


                            }
                        }

                        sres.wtAvg[col] = totVolAdjustedWt / totVol;
                        sres.total[col] = tot;
                        sres.ave[col] = tot / dataRecords;
                        sres.totVolArr[col] = totVol;
                        sres.totTonneArr[col] = tonnes;

                        sres.dataRecordsUsed[col] = dataRecords;
                        sres.maxCoord = aSlice.sliceMax;
                        sres.minCoord = aSlice.sliceMin;
                        sres.midCoord = aSlice.sliceCentre;


                    }
                    //sw.WriteLine("\nSummary: ");
                    //sw.WriteLine("Ave, " + sres.ave[0]);
                    //sw.WriteLine("wtAvg, " + sres.wtAvg[0]);
                    //sw.WriteLine("Records, " + sres.dataRecordsUsed[0]);
                    //sw.WriteLine("Tot volume, " + sres.totVolArr[0]);
                    //sw.WriteLine("Tot tonnes, " + sres.totTonneArr[0]);
               // }
            
            return sres;


        }
示例#2
0
        internal List<SliceData> SliceBy(int colNum, float sliceWidth, float startPosition, float endPosition, out string messages, BackgroundWorker workerProcessData, int startPerc, int endPerc, string statsusTagMessage)
        {
            List<SliceData> rowIDsBySlice = new List<SliceData>();
            Object ob = columnData[colNum];
            messages = "";

            

            if (ob.GetType() == floatTypeColumn)
            {
                DataColumn<float> col = (DataColumn<float>)ob;
                int numSlices = 0;
                float currentPosition = startPosition;
                float estNumSlices = (endPosition - startPosition) / sliceWidth;

                int tot = (int)(col.ColumnCount() * estNumSlices);
                float scaleWidth = endPerc - startPerc;
                float topScale = scaleWidth / tot;
                int reportingInterval = 10;
                int reportCounter = 0;

                int pCount = 0;
                while (currentPosition <= endPosition)
                {
                    reportCounter++;
                    List<int> rowIDs = new List<int>();
                    int rowNum = 0;
                    float halfWidth = sliceWidth / 2.0f;

                    float limA = currentPosition; // (currentPosition - halfWidth);
                    float limB = currentPosition + sliceWidth; //(currentPosition + halfWidth);
                    
                    messages += "Examining slice " + numSlices + " bewtween " + limA + " and " + limB + "\n";
                    foreach (float cv in col.GetDataList())
                    {
                        pCount++;
                        if (cv > limA && cv <= limB)
                        {
                            // match
                            rowIDs.Add(rowNum);
                        }
                        rowNum++;
                    }
                    SliceData sd = new SliceData();
                    sd.sliceMin = limA;
                    sd.sliceMax = limB;
                    sd.sliceCentre = currentPosition;
                    sd.rowIDList = rowIDs;
                    rowIDsBySlice.Add(sd);
                    currentPosition += sliceWidth;

                    messages += "Slice " + numSlices + " has " + rowIDs.Count + " records\n";
                    if (reportCounter == reportingInterval)
                    {
                        float perc = (pCount * topScale) + startPerc;
                        workerProcessData.ReportProgress((int)(perc), "Slice " + (numSlices) + " of " + estNumSlices);
                        reportCounter = 0;
                    }
                    numSlices++;
                }

                messages += numSlices + " slices.";
            }

            return rowIDsBySlice;

        }