Esempio n. 1
0
        public void graphGoverningDistress(object sender, EventArgs e)
        {
            ChooseRoadForm roadChooser = new ChooseRoadForm("What Road Type?", "Select a Road Surface Type");
            string         thisSql     = moduleRoads.GetSelectAllSQL();

            if (roadChooser.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string    roadType  = roadChooser.chooseRoad();
                    DataTable roadTable = Database.GetDataByQuery(Project.conn, thisSql);
                    var       roads     = roadTable.Select("surface = '" + roadType + "'");

                    if (roads.Length == 0)
                    {
                        MessageBox.Show("No graph could be generated because there are no roads of type " + roadType + ".", "No Roads", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    Dictionary <string, string[]> distressGroup = new Dictionary <string, string[]>()
                    {
                        { "Asphalt", distressAsphalt },
                        { "Gravel", distressGravel },
                        { "Concrete", distressConcrete }
                    };
                    Dictionary <string, double> distressedArea = new Dictionary <string, double>();
                    double totalArea  = 0.0;
                    double noDistress = 0.0;
                    for (int i = 0; i < distressGroup[roadType].Length; i++)
                    {
                        distressedArea.Add(distressGroup[roadType][i], 0.0);
                    }
                    foreach (DataRow row in roads)
                    {
                        double area = Util.ToDouble(row["length"].ToString()) * Util.ToDouble(row["width"].ToString());
                        totalArea += area;
                        int[] dvs = new int[9];
                        for (int i = 0; i < 9; i++)
                        {
                            dvs[i] = Util.ToInt(row["distress" + (i + 1).ToString()].ToString());
                        }
                        string governingDistress = moduleRoads.GetGoverningDistress(dvs, row["surface"].ToString());
                        if (string.IsNullOrEmpty(governingDistress))
                        {
                            noDistress += area;
                        }
                        else
                        {
                            distressedArea[governingDistress] += area;
                        }
                    }
                    DataTable results = new DataTable();
                    results.Columns.Add("Distribution");
                    for (int i = 0; i < distressGroup[roadType].Length; i++)
                    {
                        results.Columns.Add(distressGroup[roadType][i]);
                    }
                    results.Columns.Add("No Distress");
                    DataRow totalsRow     = results.NewRow();
                    DataRow percentageRow = results.NewRow();
                    totalsRow["Distribution"]     = "Area (sqr. ft.)";
                    percentageRow["Distribution"] = "Percentage";
                    string[] domain = new string[distressGroup[roadType].Length + 1];
                    double[] range  = new double[distressGroup[roadType].Length + 1];
                    for (int i = 0; i < distressGroup[roadType].Length; i++)
                    {
                        totalsRow[distressGroup[roadType][i]]     = distressedArea[distressGroup[roadType][i]];
                        percentageRow[distressGroup[roadType][i]] = Math.Round(distressedArea[distressGroup[roadType][i]] / totalArea, 3) * 100;
                        domain[i] = distressGroup[roadType][i];
                        range[i]  = Math.Round(distressedArea[distressGroup[roadType][i]] / totalArea, 3) * 100;
                    }
                    totalsRow["No Distress"]     = noDistress;
                    percentageRow["No Distress"] = Math.Round(noDistress / totalArea, 3) * 100;
                    results.Rows.Add(totalsRow);
                    results.Rows.Add(percentageRow);
                    domain[distressGroup[roadType].Length] = "No Distress";
                    range[distressGroup[roadType].Length]  = Math.Round(noDistress / totalArea, 3) * 100;
                    FormGraphDisplay graph = new FormGraphDisplay(results, domain, range, Util.UppercaseFirst(roadType) + " Road Governing Distress Distribution");
                    graph.Show();
                }
                catch (Exception err)
                {
                    Log.Error("Problem getting data from database " + err.ToString());
                }
            }
        }
Esempio n. 2
0
        public void addRows(DataRow nr, DataRow row, string surfaceType = "")
        {
            nr["ID"]           = row["TAMSID"];
            nr["Name"]         = row["name"];
            nr["Width (ft)"]   = row["width"];
            nr["Length (ft)"]  = row["length"];
            nr["Lanes"]        = row["lanes"];
            nr["Speed Limit"]  = row["speed_limit"];
            nr["From Address"] = row["from_address"];
            nr["To Address"]   = row["to_address"];
            nr["Surface"]      = row["surface"];
            nr["RSL"]          = row["rsl"];
            nr["Functional Classification"] = row["type"];
            nr["Notes"]       = truncateNote(row);
            nr["Survey Date"] = row["survey_date"];
            nr["Photo"]       = row["photo"];
            if (surfaceType == "")
            {
                nr["Fat/Spa/Pot"] = row["distress1"];
                nr["Edg/Joi/Rut"] = row["distress2"];
                nr["Lon/Cor/X-S"] = row["distress3"];
                nr["Pat/Bro/Dra"] = row["distress4"];
                nr["Pot/Fau/Dus"] = row["distress5"];
                nr["Dra/Lon/Agg"] = row["distress6"];
                nr["Tra/Tra/Cor"] = row["distress7"];
                nr["Block/Crack"] = row["distress8"];
                nr["Rutti/Patch"] = row["distress9"];
            }
            if (surfaceType == "Asphalt")
            {
                nr["Fatigue"]      = row["distress1"];
                nr["Edge"]         = row["distress2"];
                nr["Longitudinal"] = row["distress3"];
                nr["Patches"]      = row["distress4"];
                nr["Potholes"]     = row["distress5"];
                nr["Drainage"]     = row["distress6"];
                nr["Transverse"]   = row["distress7"];
                nr["Block"]        = row["distress8"];
                nr["Rutting"]      = row["distress9"];
            }
            if (surfaceType == "Concrete")
            {
                nr["Spalling"]     = row["distress1"];
                nr["Joint Seal"]   = row["distress2"];
                nr["Corners"]      = row["distress3"];
                nr["Broken"]       = row["distress4"];
                nr["Faulting"]     = row["distress5"];
                nr["Longitudinal"] = row["distress6"];
                nr["Transverse"]   = row["distress7"];
                nr["Cracking"]     = row["distress8"];
                nr["Patches"]      = row["distress9"];
            }

            if (surfaceType == "Gravel")
            {
                nr["Potholes"]  = row["distress1"];
                nr["Rutting"]   = row["distress2"];
                nr["X-Section"] = row["distress3"];
                nr["Drainage"]  = row["distress4"];
                nr["Dust"]      = row["distress5"];
                nr["Aggregate"] = row["distress6"];
                nr["Corrugate"] = row["distress7"];
            }
            double area = Util.ToDouble(row["width"].ToString()) * Util.ToDouble(row["length"].ToString());

            nr["Area (yds\u00b2)"] = area / 9;
            int[] dvs = new int[9];
            for (int i = 0; i < 9; i++)
            {
                dvs[i] = Util.ToInt(row["distress" + (i + 1).ToString()].ToString());
            }
            nr["Governing Distress"] = moduleRoads.GetGoverningDistress(dvs, row["surface"].ToString());
            nr["Cost"] = 0;
            if (!row["suggested_treatment"].ToString().Contains("null") && !string.IsNullOrWhiteSpace(row["suggested_treatment"].ToString()))
            {
                nr["Treatment"] = row["suggested_treatment"];
                string treatment = row["suggested_treatment"].ToString();

                double treatmentCost = 0.0;
                if (treatment == "Routine")
                {
                    treatmentCost = 0.56;
                }
                if (treatment == "Patching")
                {
                    treatmentCost = 0.67;
                }
                if (treatment == "Preventative")
                {
                    treatmentCost = 2.08;
                }
                if (treatment == "Preventative with Patching")
                {
                    treatmentCost = 2.75;
                }
                if (treatment == "Rehabilitation")
                {
                    treatmentCost = 9.57;
                }
                if (treatment == "Reconstruction")
                {
                    treatmentCost = 18.4;
                }
                try
                {
                    if (treatmentCost == 0.0 && treatment != "Nothing")
                    {
                        DataTable tc = Database.GetDataByQuery(Project.conn, "SELECT cost FROM treatments " + "WHERE name LIKE '" + treatment + "';");
                        treatmentCost = Util.ToDouble(tc.Rows[0]["cost"].ToString());
                    }
                }
                catch (Exception err)
                {
                    Log.Error("Problem getting data from database " + err.ToString());
                }


                double estCost = area * treatmentCost / 9;
                if (estCost > 1000000)
                {
                    nr["Cost"] = Math.Round(estCost / 1000000, 2).ToString() + "M";
                }
                else if (estCost > 1000)
                {
                    nr["Cost"] = Math.Round(estCost / 1000).ToString() + "k";
                }
                else
                {
                    nr["Cost"] = Math.Round(estCost).ToString();
                }
            }
        }