Esempio n. 1
0
        public List <EHSProfilePeriod> SelectProfilePeriodList(EHSProfile profile, DateTime fromDate, DateTime toDate)
        {
            List <EHSProfilePeriod> periodList = new List <EHSProfilePeriod>();

            foreach (WebSiteCommon.DatePeriod pd in WebSiteCommon.CalcDatePeriods(fromDate, toDate, DateIntervalType.month, DateSpanOption.SelectRange, ""))
            {
                profile.LoadPeriod(pd.FromDate);
                // profile.MapPlantAccountingInputs(true, true);
                periodList.Add(profile.InputPeriod);
            }

            return(periodList);
        }
Esempio n. 2
0
        public int MetricSeries(DateTime fromDate, DateTime toDate, decimal[] plantArray)
        {
            int         status = 0;
            int         item   = 0;
            GaugeSeries series;

            this.Results.Initialize();

            QSAttribute atr;
            bool        isAttribute;

            if ((isAttribute = Enum.TryParse(this.Calculation, out atr)) == false)
            {
                this.SetScopeRef(this.Calculation);
            }

            List <object> foList = new List <object>();
            string        text   = "";

            switch (this.Seriesorder)
            {
            case QSCalcsCtl.SeriesOrder.MeasureSeries:
                switch (this.MetricScope)
                {
                case "plant":
                    foList = this.RecordList.Where(r => plantArray.Contains(r.PlantResponsible.PLANT_ID)).Select(r => (object)r.PlantResponsible).Distinct().ToList();
                    break;

                case "plantResp":
                    foList = this.RecordList.Select(r => (object)r.PlantResponsible).Distinct().ToList();
                    break;

                case "plantDetect":
                    foList = this.RecordList.Select(r => (object)r.Plant).Distinct().ToList();
                    break;

                case "person":
                    foList = this.RecordList.Select(r => (object)r.Person).Distinct().ToList();
                    break;

                case "partType":
                    List <string> pat = this.RecordList.Select(r => r.QIIssue.PART_TYPE).Distinct().ToList();
                    foList = SQMModelMgr.SelectPartAttributeList("TYPE", "", false).Where(l => pat.Contains(l.ATTRIBUTE_CD)).Select(l => (object)l).ToList();
                    break;

                case "month":
                    foreach (WebSiteCommon.DatePeriod pd in WebSiteCommon.CalcDatePeriods(fromDate, toDate, DateIntervalType.month, DateSpanOption.FYEffTimespan, ""))
                    {
                        foList.Add(pd);
                    }
                    break;

                default:
                    if ((isAttribute = Enum.TryParse(this.MetricScope, out atr)))
                    {
                        this.SetAttributeRef(atr);
                        foreach (KeyValuePair <string, string> xlat in this.Calc.AttributeXref)
                        {
                            foList.Add(xlat);
                        }
                    }
                    break;
                }

                foreach (string factor in this.GetFactorsByScope(this.Calculation))
                {
                    series = new GaugeSeries().CreateNew(1, factor, "");
                    foreach (object fo in foList)
                    {
                        switch (this.MetricScope)
                        {
                        case "plant":
                        case "plantDetect":
                        case "plantResp":
                            text = ((PLANT)fo).PLANT_NAME;
                            this.FilterByPlant(new decimal[1] {
                                ((PLANT)fo).PLANT_ID
                            });
                            break;

                        case "person":
                            text = SQMModelMgr.FormatPersonListItem((PERSON)fo);
                            this.FilterByPerson(new decimal[1] {
                                ((PERSON)fo).PERSON_ID
                            });
                            break;

                        case "partType":
                            text = ((PART_ATTRIBUTE)fo).ATTRIBUTE_VALUE;
                            this.FilterByPartType(new string[1] {
                                ((PART_ATTRIBUTE)fo).ATTRIBUTE_CD
                            });
                            break;

                        case "month":
                            WebSiteCommon.DatePeriod pd = (WebSiteCommon.DatePeriod)fo;
                            text = pd.Label;
                            this.FilterByDate(pd.FromDate, pd.ToDate);
                            break;

                        default:
                            text = ((KeyValuePair <string, string>)fo).Value;
                            this.FilterByAttribute(this.MetricScope, new string[1] {
                                ((KeyValuePair <string, string>)fo).Key
                            });
                            break;
                        }

                        this.MetricFactor(plantArray, new decimal[0] {
                        }, fromDate, toDate, factor, "", null);
                        if (this.Results.ValidResult)
                        {
                            series.ItemList.Add(new GaugeSeriesItem().CreateNew(1, item++, text, this.Results));
                        }
                    }
                    this.Results.metricSeries.Add(series);
                }
                break;

            case QSCalcsCtl.SeriesOrder.SumAll:
                if (isAttribute)
                {
                    this.InitCalc();
                    this.SetAttributeRef(atr);
                    GaugeSeries sumSeries = new GaugeSeries().CreateNew(0, "", "");
                    foreach (KeyValuePair <string, string> xlat in this.Calc.AttributeXref)
                    {
                        if (this.MetricFactor(plantArray, new decimal[0] {
                        }, fromDate, toDate, this.Calculation, xlat.Key, null) > 0)
                        {
                            sumSeries.ItemList.Add(new GaugeSeriesItem().CreateNew(1, item++, 0, this.Results.Result, xlat.Value));
                        }
                    }
                    if (sumSeries.ItemList.Count > 0)
                    {
                        this.Results.metricSeries.Add(sumSeries);
                    }

                    if (this.Results.metricSeries.Count > 0)
                    {
                        this.Results.ValidResult = true;
                    }

                    if (this.Stat == SStat.pct)      // transform series from values to percentages
                    {
                        this.Results.TransformSeries(this.Stat, EHSCalcsCtl.SeriesOrder.MeasureSeries);
                    }
                }
                break;

            default:
                break;
            }
            return(status);
        }