Example #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> dhrs = new List<DHr>();
            string key = "";
            if ((DA.GetDataList(0, dhrs)) && (DA.GetData(1, ref key))) {
                float maxval = dhrs[0].val(key);
                float minval = dhrs[0].val(key);
                int max_day = 0;
                int min_day = 0;
                for (int n = 1; n < dhrs.Count; n++) {
                    float val = dhrs[n].val(key);
                    if (val > maxval) {
                        maxval = val;
                        max_day = dhrs[n].day_of_year;
                    }
                    if (val < minval) {
                        minval = val;
                        min_day = dhrs[n].day_of_year;
                    }
                }
                HourMask max_mask = new HourMask();
                max_mask.maskByDayOfYear(max_day, max_day);
                HourMask min_mask = new HourMask();
                min_mask.maskByDayOfYear(min_day, min_day);

                List<DHr> maxHrs = new List<DHr>();
                foreach (DHr hr in dhrs) if (max_mask.eval(hr)) maxHrs.Add(hr);
                List<DHr> minHrs = new List<DHr>();
                foreach (DHr hr in dhrs) if (min_mask.eval(hr)) minHrs.Add(hr);

                DA.SetDataList(0, maxHrs);
                DA.SetDataList(1, minHrs);
            }
        }
Example #2
0
        private void CalculateStats(List<DHr> dhrs, string[] keys, Dictionary<string, List<DHr>> stat_hours_dict, HourMask mask, int assigned_hour_of_year, bool calculate_mode = false)
        {
            Dictionary<string, List<float>> value_dict = new Dictionary<string, List<float>>();
            foreach (string key in keys) { value_dict.Add(key, new List<float>()); }
            int count = 0;
            List<int> a = new List<int>();
            List<int> r = new List<int>();
            List<int> g = new List<int>();
            List<int> b = new List<int>();
            foreach (DHr hour in dhrs) {
                if (mask.eval(hour)) {
                    count++;
                    a.Add(hour.color.A);
                    r.Add(hour.color.R);
                    g.Add(hour.color.G);
                    b.Add(hour.color.B);
                    foreach (string key in keys) { value_dict[key].Add(hour.val(key)); }
                }
            }
            Color c = Color.FromArgb((int)a.Average(), (int)r.Average(), (int)g.Average(), (int)b.Average());

            DHr meanHr = new DHr(assigned_hour_of_year); meanHr.is_surrogate = true; meanHr.color = c;
            DHr modeHr = new DHr(assigned_hour_of_year); modeHr.is_surrogate = true; modeHr.color = c;
            DHr highHr = new DHr(assigned_hour_of_year); highHr.is_surrogate = true; highHr.color = c;
            DHr uqHr = new DHr(assigned_hour_of_year); uqHr.is_surrogate = true; uqHr.color = c;
            DHr medianHr = new DHr(assigned_hour_of_year); medianHr.is_surrogate = true; medianHr.color = c;
            DHr lqHr = new DHr(assigned_hour_of_year); lqHr.is_surrogate = true; lqHr.color = c;
            DHr lowHr = new DHr(assigned_hour_of_year); lowHr.is_surrogate = true; lowHr.color = c;
            DHr sumHr = new DHr(assigned_hour_of_year); sumHr.is_surrogate = true; sumHr.color = c;

            if (calculate_mode) {
                foreach (string key in keys) {
                    value_dict[key].Sort();
                    meanHr.put(key, value_dict[key].Mean());
                    highHr.put(key, value_dict[key][value_dict[key].Count - 1]);
                    uqHr.put(key, value_dict[key].Quartile(0.75f));
                    medianHr.put(key, value_dict[key].Median());
                    lqHr.put(key, value_dict[key].Quartile(0.25f));
                    lowHr.put(key, value_dict[key][0]);
                    sumHr.put(key, value_dict[key].Sum());

                    List<float> modes = value_dict[key].Modes().ToList<float>();
                    //if (modes.Count > 1) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, String.Format("Multiple values associated with the key '{0}' occur equally often, resulting in multiple Mode values.  I've returned the first mode encountered", key));
                    if (modes.Count >= 1) modeHr.put(key, modes[0]);
                    else {
                        //this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Format("Each value associated with the key '{0}' is unique.  Unable to calculate Mode", key));
                        modeHr.put(key, MDHr.INVALID_VAL);
                    }
                }
            }
            stat_hours_dict["meanHrs"].Add(meanHr);
            if (calculate_mode) stat_hours_dict["modeHrs"].Add(modeHr);
            stat_hours_dict["highHrs"].Add(highHr);
            stat_hours_dict["uqHrs"].Add(uqHr);
            stat_hours_dict["medianHrs"].Add(medianHr);
            stat_hours_dict["lqHrs"].Add(lqHr);
            stat_hours_dict["lowHrs"].Add(lowHr);
            stat_hours_dict["sumHrs"].Add(sumHr);
        }
Example #3
0
 protected override void SolveInstance(IGH_DataAccess DA)
 {
     List<DHr> hrsIn = new List<DHr>();
     HourMask mask = new HourMask();
     mask.fillMask(true);
     DA.GetData(1, ref mask);
     if (DA.GetDataList(0, hrsIn)) {
         List<DHr> hrsOut = new List<DHr>();
         foreach (DHr hour in hrsIn) if (mask.eval(hour)) hrsOut.Add(hour);
         DA.SetDataList(0, hrsOut);
     }
 }