Esempio n. 1
0
 protected override void SolveInstance(IGH_DataAccess DA)
 {
     DHr dhr = new DHr();
     if (DA.GetData(0, ref dhr))
     {
         DA.SetData(0, dhr.hr);
         DA.SetDataList(1, dhr.keys);
         DA.SetDataList(2, dhr.values);
         DA.SetData(3, dhr.color);
         DA.SetData(4, dhr.pos);
     }
 }
Esempio n. 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<int> hrs = new List<int>();
            List<string> keys = new List<string>();
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Number> valtree = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Number>();
            if ((DA.GetDataList(1, keys)) && (DA.GetDataTree(2, out valtree)) && (DA.GetDataList(0, hrs)))
            {

                bool has_color = false;
                List<Color> colors = new List<Color>();
                has_color = DA.GetDataList(4, colors);

                bool has_pt = false;
                List<Point3d> points = new List<Point3d>();
                has_pt = DA.GetDataList(4, points);

                if (hrs.Count != valtree.Branches.Count) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "List matching error.  Hours and Vals must match.  If you pass in more than one hour number, then you must pass in a tree of values with one branch per hour number, and vice-versa.");
                else foreach (List<GH_Number> branch in valtree.Branches) if (keys.Count != branch.Count) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "List matching error.  Keys and Vals must offer lists of the same length.  If you pass in a tree of values, each branch must contain a list of the same length as the list of keys.");
                        else
                        {
                            if (((has_color) && (colors.Count != hrs.Count)) || ((has_pt) && (points.Count != hrs.Count)))
                            {
                                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "List matching error.");
                                return;
                            }
                            List<DHr> hours = new List<DHr>();
                            for (int n = 0; n < valtree.Branches.Count; n++)
                            {
                                DHr hr = new DHr(hrs[n]);
                                for (int m = 0; m < keys.Count; m++) hr.put(keys[m], (float)valtree.Branches[n][m].Value);
                                if (has_color) hr.color = colors[n];
                                if (has_pt) hr.pos = points[n];
                                hours.Add(hr);
                            }
                            DA.SetDataList(0, hours);
                        }
            }
        }
Esempio n. 3
0
    public void FillPortCall()
    {
        int       Port_Call_Id = UDFLib.ConvertToInteger(Request.QueryString["StatusID"].ToString());
        DataTable dt           = objPortCall.Get_PortCall_List(Port_Call_Id, UDFLib.ConvertToInteger(ddlVessel.SelectedValue));

        //if(Port_Call_Id == 0)
        //    chkAutoDate.Enabled=false;
        if (dt.Rows.Count > 0)
        {
            tr1.Visible = true;
            ViewState["ReturnPortCallID"] = Request.QueryString["StatusID"].ToString();
            char[]   delimiterChars = { ' ', ',', '.', ':', '\t' };
            string   ArrivalDate, BerthingDate, DepartureDate;
            string[] ADate, BDate, DDate;
            string   Arrhr, Arrmin, Brhr, BrMin, DHr, DMin;

            if (dt.Rows[0]["Arrival"].ToString() != "")
            {
                ArrivalDate = dt.Rows[0]["Arrival"].ToString();
                DateTime dtArr = Convert.ToDateTime(dt.Rows[0]["Arrival"].ToString());
                ADate = ArrivalDate.Split(delimiterChars);
                //This change has been done to change the date format as per user selection
                dtpArrival.Text          = UDFLib.ConvertUserDateFormat(Convert.ToString(dtArr));
                Arrhr                    = ADate[1].ToString();
                Arrmin                   = ADate[2].ToString();
                ddlArrHour.SelectedValue = Arrhr.ToString();
                ddlArrMin.SelectedValue  = Arrmin.ToString();
            }
            else
            {
                if (ViewState["dtpArrival"] != null)
                {
                    //This change has been done to change the date format as per user selection
                    dtpArrival.Text = UDFLib.ConvertUserDateFormat(Convert.ToString(ViewState["dtpArrival"]));

                    ddlArrHour.SelectedValue = ViewState["ddlArrHour"].ToString();
                    ddlArrMin.SelectedValue  = ViewState["ddlArrMin"].ToString();
                }
            }
            if (dt.Rows[0]["Berthing"].ToString() != "")
            {
                BerthingDate = dt.Rows[0]["Berthing"].ToString();
                DateTime dtBer = Convert.ToDateTime(dt.Rows[0]["Berthing"].ToString());
                BDate = BerthingDate.Split(delimiterChars);
                //This change has been done to change the date format as per user selection
                dtpBerthing.Text = UDFLib.ConvertUserDateFormat(Convert.ToString(dtBer));

                Brhr  = BDate[1].ToString();
                BrMin = BDate[2].ToString();
                ddlBerthingHour.SelectedValue = Brhr.ToString();
                ddlBerthingMin.SelectedValue  = BrMin.ToString();
            }
            if (dt.Rows[0]["Departure"].ToString() != "")
            {
                DepartureDate = dt.Rows[0]["Departure"].ToString();
                DateTime dtDep = Convert.ToDateTime(dt.Rows[0]["Departure"].ToString());
                DDate = DepartureDate.Split(delimiterChars);
                //This change has been done to change the date format as per user selection
                dtpDeparture.Text = UDFLib.ConvertUserDateFormat(Convert.ToString(dtDep));
                DHr  = DDate[1].ToString();
                DMin = DDate[2].ToString();
                ddlDepHr.SelectedValue  = DHr.ToString();
                ddlDepmin.SelectedValue = DMin.ToString();
            }
            else
            {
                if (ViewState["dtpDeparture"] != null)
                {
                    //This change has been done to change the date format as per user selection
                    dtpDeparture.Text = UDFLib.ConvertUserDateFormat(Convert.ToString(ViewState["dtpDeparture"]));

                    ddlDepHr.SelectedValue  = ViewState["ddlDepHr"].ToString();
                    ddlDepmin.SelectedValue = ViewState["ddlDepmin"].ToString();
                }
            }
            DDLPort.SelectedValue = dt.Rows[0]["Port_ID"].ToString();
            if (dt.Rows[0]["Port_ID"].ToString() == "0")
            {
                txtlocation.Text       = dt.Rows[0]["Port_Name"].ToString();
                txtlocation.Visible    = true;
                chkNewLocation.Checked = true;
                DDLPort.Visible        = false;
            }
            else
            {
                txtlocation.Visible = false;
                DDLPort.Visible     = true;
                //DDLPort.Enabled = false;
            }

            //chkNewLocation.Visible = false;
            ddlCharterAgent.SelectedValue = dt.Rows[0]["Charterers_Agent"].ToString();
            ddlOwnersAgent.SelectedValue  = dt.Rows[0]["Owners_ID"].ToString();
            int warrisk   = Convert.ToInt16(dt.Rows[0]["IsWarRisk"].ToString());
            int ShipCrane = Convert.ToInt16(dt.Rows[0]["IsShipCraneReq1"].ToString());
            if (warrisk == 1)
            {
                chkWarRisk.Checked = true;
            }
            if (ShipCrane == 1)
            {
                chkShipCrane.Checked = true;
            }
            string Port_Call_Status = Convert.ToString(dt.Rows[0]["Port_Call_Status"].ToString());
            if (Port_Call_Status == "OMITTED")
            {
                chkPortCallStatus.Checked = true;
            }
            txtPortRemark.Text = dt.Rows[0]["Port_Remarks"].ToString();


            if (dt.Rows[0]["Auto_Date"].ToString() == "Y")
            {
                chkAutoDate.Checked     = true;
                dtpArrival.Enabled      = false;
                dtpBerthing.Enabled     = false;
                dtpDeparture.Enabled    = false;
                ddlArrHour.Enabled      = false;
                ddlArrMin.Enabled       = false;
                ddlBerthingHour.Enabled = false;
                ddlBerthingMin.Enabled  = false;
                ddlDepHr.Enabled        = false;
                ddlDepmin.Enabled       = false;
            }
            else
            {
                chkAutoDate.Checked     = false;
                dtpArrival.Enabled      = true;
                dtpBerthing.Enabled     = true;
                dtpDeparture.Enabled    = true;
                ddlArrHour.Enabled      = true;
                ddlArrMin.Enabled       = true;
                ddlBerthingHour.Enabled = true;
                ddlBerthingMin.Enabled  = true;
                ddlDepHr.Enabled        = true;
                ddlDepmin.Enabled       = true;
            }
        }
    }
Esempio n. 4
0
 protected override void SolveInstance(IGH_DataAccess DA)
 {
     DHr dhr = new DHr();
     if (DA.GetData(0, ref dhr)) DA.SetData(0, dhr.pos);
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr>[] inputs = new List<DHr>[Params.Input.Count];
            for (int i = 0; i < Params.Input.Count; i++) {
                List<DHr> hrs = new List<DHr>();
                if (DA.GetDataList(i, hrs)) { inputs[i] = hrs; }
            }

            int hr_count = inputs[0].Count;
            int first_hour_int = inputs[0][0].hr;
            for (int i = 1; i < inputs.Length; i++) {
                if (inputs[i].Count != hr_count) hr_count = -1;
                if (inputs[i][0].hr != first_hour_int) first_hour_int = -999;
            }

            if ((hr_count > 0) && (first_hour_int >= -1)) {
                DHr[] hrsOut = new DHr[hr_count];
                for (int h = 0; h < hr_count; h++) hrsOut[h] = (new DHr(inputs[0][h].hr));

                for (int i = 0; i < inputs.Length; i++) {
                    string input_nickname = Params.Input[i].NickName;
                    for (int h = 0; h < hr_count; h++) {
                        DHr hr = inputs[i][h];
                        foreach (string key in hr.keys) {
                            if (input_nickname == "none") hrsOut[h].put(key, hr.val(key));
                            else hrsOut[h].put((key + " :: " + input_nickname).ToLowerInvariant().Trim(), hr.val(key));
                        }
                    }
                }
                DA.SetDataList(0, hrsOut);
            } else {
                // here we handle

                List<int> hour_indices = new List<int>(); // holds the combined list of hours represented in all lists
                foreach (List<DHr> hours in inputs) {
                    foreach (DHr hr in hours) if (!hour_indices.Contains(hr.hr)) hour_indices.Add(hr.hr);
                }

                DHr[] hrsOut = new DHr[hour_indices.Count];
                foreach (int hour_index in hour_indices) hrsOut[hour_index] = (new DHr(hour_index));

                for (int i = 0; i < inputs.Length; i++) {
                    List<DHr> hours = inputs[i];
                    string input_nickname = Params.Input[i].NickName;
                    foreach (int hour_index in hour_indices) {
                        DHr hr = hours.Find(hr_src => hr_src.hr == hour_index);
                        foreach (string key in hr.keys) {
                            if (input_nickname == "none") hrsOut[hour_index].put(key, hr.val(key));
                            else hrsOut[hour_index].put((key + " :: " + input_nickname).ToLowerInvariant().Trim(), hr.val(key));
                        }
                    }
                }
                DA.SetDataList(0, hrsOut);
            }
        }
Esempio n. 7
0
 protected override void SolveInstance(IGH_DataAccess DA)
 {
     DHr hrIn = new DHr();
     if (DA.GetData(1, ref hrIn)) {
         DHr hrOut = new DHr(hrIn);
         hrOut.clear();
         List<string> keys_to_keep = new List<string>();
         DA.GetDataList(0, keys_to_keep);
         foreach (string key in keys_to_keep) {
             if (hrIn.containsKey(key)) hrOut.put(key, hrIn.val(key));
             else this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "key not found in given hour: " + key + "\nIf you are streaming from a panel component did you remember to uncheck the 'multiline data' option?");
         }
         DA.SetData(0, hrOut);
     }
 }
Esempio n. 8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> dhrs = new List<DHr>();
            int scope = -1;
            if ((DA.GetDataList(0, dhrs)) && (DA.GetData(1, ref scope))) {
                string[] commonKeys = DHr.commonkeys(dhrs.ToArray());

                List<DHr> hrsOut = new List<DHr>();
                for (int n = 0; n < dhrs.Count; n++) {
                    DHr dhr = new DHr(dhrs[n]);
                    foreach (string key in commonKeys) {
                        float sum = 0;
                        for (int di = -scope / 2; di <= scope / 2; di++) {
                            int m = n + di;
                            if (m < 0) m = dhrs.Count + m;
                            if (m > dhrs.Count - 1) m = m - dhrs.Count;
                            sum += dhrs[m].val(key);
                        }
                        sum = sum / ((float)scope + 1);
                        dhr.put(key, sum);
                    }
                    hrsOut.Add(dhr);
                }

                DA.SetDataList(0, hrsOut);
            }
        }
Esempio n. 9
0
        private bool ParseFilepath()
        {
            if (!FilepathValid()) { return false; }
            col_mapping = new Dictionary<string, Dictionary<string, int>>();

            // get a list of the column headers
            List<string> headers;
            using (StreamReader headreader = new StreamReader(new FileStream(filepath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite))) { headers = new List<string>(headreader.ReadLine().Split(',')); }

            for (int n = 0; n < headers.Count; n++)
            {
                if (headers[n].Contains(":"))
                {
                    // process zone name
                    string zone_name = headers[n].Split(':')[0].Trim();
                    zone_name = zone_name.ToLower();
                    zone_name = DHr.cleankey(zone_name);

                    // process col name
                    string col_name = headers[n].Split(':')[1];
                    int offset = col_name.IndexOf("(");
                    if (offset >= 0)
                        col_name = col_name.Substring(0, offset);
                    col_name = col_name.Trim();
                    col_name = col_name.ToLower();
                    col_name = DHr.cleankey(col_name);

                    // register this column header in our zone_dict
                    if (!col_mapping.ContainsKey(zone_name)) { col_mapping.Add(zone_name, new Dictionary<string, int>()); }
                    col_mapping[zone_name].Add(col_name, n);
                }
            }

            #region //CLEAN COLUMN HEADERS
            // eplus does some stupid stuff with the way it names column headers.  let's see if we can fix that.
            // our col_mapping dict may have some duplicate entries such as "lower_zone" and then later "lower_zone lights2"
            // remove "lower_zone lights2", and then move all the entries in into "lower_zone"

            List<string> zonenames_to_delete = new List<string>();
            foreach (KeyValuePair<string, Dictionary<string, int>> entry in col_mapping)
            {
                string this_zonename = entry.Key;
                foreach (string that_zonename in col_mapping.Keys)
                {
                    if (this_zonename.Contains(that_zonename) && (!this_zonename.Equals(that_zonename, StringComparison.OrdinalIgnoreCase)))
                    {
                        // we've found a duplicate.  copy over all the entries, with the keys prepended by this zonename
                        char[] charsToTrim = { '_', ' ', ':'};
                        string prefix = this_zonename.Replace(that_zonename, "").Trim(charsToTrim);
                        foreach (KeyValuePair<string, int> mapping in entry.Value) { col_mapping[that_zonename].Add(prefix + " : " + mapping.Key, mapping.Value); }
                        zonenames_to_delete.Add(this_zonename);
                        break;
                    }
                }
            }
            foreach (string key in zonenames_to_delete) { col_mapping.Remove(key); }
            #endregion

            zone_hours = new Dictionary<string, List<DHr>>();
            foreach (string key in col_mapping.Keys) { zone_hours.Add(key, new List<DHr>()); } // empty list of hours for each zone

            StreamReader reader = new StreamReader(new FileStream(filepath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite));
            string line;
            int lnum = 0;
            bool sizing_complete = false;
            while ((line = reader.ReadLine()) != null)
            {
                if (lnum >= header_lines)
                {
                    string[] linedata = line.Split(',');

                    DateTime dt = Util.baseDatetime();
                    string[] dt_strings = linedata[0].Trim().Split(new char[] {' '},StringSplitOptions.RemoveEmptyEntries);
                    if (!DateTime.TryParse(dt_strings[0] + "/" + Util.defaultYear, out dt)) // we're adding the default year here
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "could not parse datetime on line " + lnum);
                        return false;
                    }
                    int h = 0;
                    if (Int32.TryParse(dt_strings[1].Split(':')[0],out h)){dt = dt.AddHours(h);} else {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "could not parse datetime on line " + lnum);
                        return false;
                    }
                    int hourOfYear = Util.hourOfYearFromDatetime(dt);
                    if ((hourOfYear > 8759) || (hourOfYear < 0)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Found an odd-looking datetime on line " + lnum); }
                    if ((!sizing_complete) && (hourOfYear == 0)) { sizing_complete = true; }  // check if the two-day sizing period is done with
                    if (sizing_complete)
                    {
                        foreach (KeyValuePair<string, Dictionary<string, int>> column_dict in col_mapping)
                        {
                            DHr hr = new DHr(hourOfYear);
                            try
                            {
                                foreach (KeyValuePair<string, int> column in column_dict.Value)
                                {
                                    hr.put(column.Key, float.Parse(linedata[column.Value]));
                                }
                            }
                            catch
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "parse error on line " + lnum);
                                return false;
                            }
                            zone_hours[column_dict.Key].Add(hr);
                        }
                    }
                }
                lnum++;
            }
            return true;
        }