Пример #1
0
        /// <summary>
        ///SIID AWC: Negative number less than - 10(negate, subtract 10) No hardcoded upper range
        ///SIID LotSize: -Either AWC or LOTSIZE depending on indooor / outdoor, can use the same range for setting
        ///
        /// SIID stores AWX/LotSize, Steward decides what to do with it and with the tiered rates
        /// </summary>
        /// <param name="Device"></param>
        /// <param name="AWCOrLot"></param>
        public void SetAWC_LotSize(SiidDevice Device, double AWCOrLot)
        {
            //

            double AWC_Lot = 8000;

            AWC_Lot = -(AWCOrLot + 10);


            AWC_Lot = Double.Parse(AWC_Lot.ToString("0.00000"));
            Device.UpdateExtraData("AWCOrLot", AWC_Lot.ToString());
            Device.UpdateExtraData("showTier", "True");
            UpdateDisplay(Device);
            CheckForReset(Device);
        }
Пример #2
0
        /// <summary>
        /// SIID fixed cost: Between 1000 and 2000(subtract 1000 round to 4 decmil, range from 0 to 1000)
        /// </summary>
        /// <param name="Device"></param>
        /// <param name="FixedCostPlus1000"></param>
        public void SetFixedCost(SiidDevice Device, double FixedCostPlus1000)
        {
            double FixedCost = 0;

            FixedCost = FixedCostPlus1000 - 1000;

            FixedCost = Double.Parse(FixedCost.ToString("0.00000"));
            Device.UpdateExtraData("FixedCost", FixedCost.ToString());
            UpdateDisplay(Device);
            CheckForReset(Device);
        }
Пример #3
0
        /// <summary>
        ///SIID Tiers(4 tiers with boundaries based on AWC or Lotsize), each tier needs an editable rate.
        ///        Tier 1 rate between 2000 and 3000(subtract 2000, round to 4 decmil, range 0 to 1000)
        ///        Tier 2 rate between 3000 and 4000(subtract 3000, round to 4 decmil, range 0 to 1000)
        ///        Tier 3 rate between 4000 and 5000(subtract 4000, round to 4 decmil, range 0 to 1000)
        ///        Tier 4 rate between 5000 and 6000(subtract 4000, round to 4 decmil, range 0 to 1000)
        /// </summary>
        /// <param name="Device"></param>
        /// <param name="TieredRate"></param>
        public void SetTieredRate(SiidDevice Device, double TieredRate)
        {
            String Tier = "RateTier";
            Double Rate = 0;

            //Tier 4 rate
            if (TieredRate >= 5000)
            {
                Rate  = TieredRate - 5000;
                Tier += "4";
            }
            //Tier 3 rate
            if (TieredRate >= 4000)
            {
                Rate  = TieredRate - 4000;
                Tier += "3";
            }
            //Tier 2 rate
            else if (TieredRate >= 3000)
            {
                Rate  = TieredRate - 3000;
                Tier += "2";
            }
            //Tier 1 rate
            else
            {
                Rate  = TieredRate - 2000;
                Tier += "1";
            }

            Rate = Double.Parse(Rate.ToString("0.0000"));
            Device.UpdateExtraData(Tier, Rate.ToString());
            Device.UpdateExtraData("showTier", "True");
            UpdateDisplay(Device);
            CheckForReset(Device);
        }
Пример #4
0
        public string parseInstances(string data)
        {
            //  Console.WriteLine("ConfigDevicePost: " + data);


            System.Collections.Specialized.NameValueCollection changed = null;
            changed = System.Web.HttpUtility.ParseQueryString(data);
            string partID = changed["id"].Split('_')[0];
            int    devId  = Int32.Parse(changed["id"].Split('_')[1]);

            if (partID == "S")
            {
                addSubrule(changed["id"]);
            }
            else if (partID == "R")
            {
                Reset(SiidDevice.GetFromListByID(Instance.Devices, devId));
            }

            else
            {
                if (partID == "ScratchPadString")
                {
                    changed["value"] = changed["value"].Replace(" ", "%2B");
                }
                SiidDevice newDevice = SiidDevice.GetFromListByID(Instance.Devices, devId);
                //check for gateway change, do something special
                if (partID == "Name")
                {
                    newDevice.Device.set_Name(Instance.host, changed["value"]);
                }
                else if (partID == "devdelete")
                {
                    Instance.host.DeleteDevice(devId);
                    SiidDevice.removeDev(Instance.Devices, devId);
                }

                else
                {
                    newDevice.UpdateExtraData(partID, changed["value"]);
                    UpdateDisplay(newDevice);
                }
            }


            return("True");
        }
Пример #5
0
        /// <summary>
        /// SIID set rate(units per dollar):		   float between 200 and 1000 (subtract 200 round to 4 decimal places), rate range between 0 and 800
        /// </summary>
        /// <param name="Device"></param>
        /// <param name="RatePlus200"></param>
        public void SetRate(SiidDevice Device, double RatePlus200)
        {
            double Rate = 0;

            //       if (RatePlus200 < 0)
            //      {
            //          Rate = RatePlus200 + 200;
            //      }
            //     else
            //        {
            Rate = RatePlus200 - 200;
            //      }
            Rate = Double.Parse(Rate.ToString("0.0000"));
            Device.UpdateExtraData("RateValue", Rate.ToString());
            UpdateDisplay(Device);
            CheckForReset(Device);
        }
Пример #6
0
        public void doLiveRule(SiidDevice Rule)
        {
            var parts = HttpUtility.ParseQueryString(Rule.Device.get_PlugExtraData_Get(Instance.host).GetNamed("SSIDKey").ToString());

            string RawNumberString  = GeneralHelperFunctions.GetValues(Instance, parts["LiveUpdateID"]);
            double CalculatedString = CalculateString(RawNumberString);

            try
            {
                String Name = Rule.Device.get_Name(Instance.host).ToLower();
                //OK should apply tiered rate to the Calculated string if appropriate.
                if (Name.Contains("water") && Name.Contains("meter") && (Name.Contains("indoor") || Name.Contains("outdoor")))
                {
                    double MeterString = Double.Parse(parts["RawValue"]);
                    CalculatedString = LiveTier(MeterString, CalculatedString, Rule);
                }
                else
                {
                    double Rate = 1;
                    if (Boolean.Parse(parts["showTier"]))
                    {
                        Rate = Double.Parse(parts["RateTier1"]);
                    }
                    else if (!String.IsNullOrEmpty(parts["RateValue"]))
                    {
                        Rate = Double.Parse(parts["RateValue"]);
                    }


                    CalculatedString = CalculatedString * Rate;
                }
            }
            catch
            {
            }
            if (Math.Abs(CalculatedString) < .00001)
            {
                CalculatedString = 0;
            }



            Rule.UpdateExtraData("LiveValue", "" + CalculatedString.ToString());
        }
Пример #7
0
        //Functions like TieredRates, but just gets the tier and applies that rate to LiveValue
        public Double LiveTier(Double MeterValue, Double LiveValue, SiidDevice Rule)
        {
            var    parts    = HttpUtility.ParseQueryString(Rule.Device.get_PlugExtraData_Get(Instance.host).GetNamed("SSIDKey").ToString());
            Double AWCorLot = Double.Parse(parts["AWCOrLot"]);
            Double Rate1    = Double.Parse(parts["RateTier1"]);
            Double Rate2    = Double.Parse(parts["RateTier2"]);
            Double Rate3    = Double.Parse(parts["RateTier3"]);

            String Name = Rule.Device.get_Name(Instance.host).ToLower();

            if (Name.Contains("indoor"))
            {
                //Indoor water meter
                //AWCOrLot is AWC
                //Final Amount = Rate1 * (Meter Value up to AWC) + Rate2 * (Meter value from AWC up to AWC*1.2) + Rate3 * (Meter value greater than AMC*1.2)
                Double Amount1 = 0;
                Double Amount2 = 0;
                Double Amount3 = 0;
                if (MeterValue > AWCorLot * 1.2)
                {
                    return(Rate3 * LiveValue);
                }
                if (MeterValue > AWCorLot)
                {
                    return(Rate2 * LiveValue);
                }
                return(Rate1 * LiveValue);
            }
            else
            {
                //Outdoor water meter, AWC
                //AWCOrLot is LotSize
                //Use lot size to calculate outdoor allotment ALT

                //ALT follows the table in the Sterling Ranch Outdoor Water Allotment Table
                //10/13/2017

                /*Lot Size      Gal/year        Apr         May         June         July       Aug     Set     Oct         Multiplier
                 * 0 - 3000     10000           700         1600        1900        2100        1900    1300    500         1
                 * 3001-4000    12500           875         2000        2375        2625        2375    1625    625         1.25
                 * 4001-5000    15000           1050        2400        2850        3150        2850    1950    750         1.5
                 * 5001-6000    27000           1890        4320        5130        5670        5130    3510    1350        2.7
                 * 6001-7000    32000           2240        5120        6080        6720        6080    4160    1600        3.2
                 * 7001-8000    39000           2730        6240        7410        8190        7410    5070    1950        3.9
                 * 8001-11000   49000           3430        7840        9310        10290       9310    6370    2450        4.9
                 * 11001-20000  60000           4200        9600        11400       12600       11400   7800    3000        6
                 * 20001-30000  80000           5600        12800       15200       16800       15200   10400   4000        8
                 * 30001 ++     100000          7000        1600        19000       21000       19000   13000   5000        10
                 *
                 */
                //Definitely a better way to do this.
                double[] MonthRate  = new double[] { 700, 1600, 1900, 2100, 1900, 1300, 500, 0, 0, 0, 0, 0 };
                String[] MonthIndex = new String[] { "4", "5", "6", "7", "8", "9", "10", "11", "12", "1", "2", "3" };
                double[] SizeCap    = new double[] { 3001, 4001, 5001, 6001, 7001, 8001, 11001, 20001, 30001 };
                double[] MultPlier  = new double[] { 1, 1.25, 1.5, 2.7, 3.2, 3.9, 4.9, 6, 8, 10 };
                int      index      = 0;
                foreach (double Cap in SizeCap)
                {
                    if (Cap > AWCorLot)
                    {
                        break;
                    }
                    index++;
                }
                double Mult = MultPlier[index];
                //  int thisMonth = int.Parse(DateTime.Now.ToString("MM")); //this is the month number


                double MonthVal = MonthRate[Array.IndexOf(MonthIndex, DateTime.Now.Month.ToString())];


                double ALT = Mult * MonthVal;
                Rule.UpdateExtraData("OutdoorWaterBudget", "" + ALT);
                //ALT is the budget. Want to return this to STEWARD also.
                //Final Amount = Rate1 * (Meter Value up to ALT) + Rate2 * (Meter value from ALT up to ALT*1.2) + Rate3 * (Meter value from ALT*1.2 to 1.4*ALT) + Rate4 * (Meter value greater than AMC*1.4)

                if (ALT > 0)
                {
                    Double Rate4 = Double.Parse(parts["RateTier4"]);

                    if (MeterValue > AWCorLot * 1.4)
                    {
                        return(Rate4 * LiveValue);
                    }
                    if (MeterValue > AWCorLot * 1.2)
                    {
                        return(Rate3 * LiveValue);
                    }
                    if (MeterValue > AWCorLot)
                    {
                        return(Rate2 * LiveValue);
                    }
                    return(Rate1 * LiveValue);
                }
                else
                { //If the allowence is zero, just apply Rate1 to full amount
                    return(LiveValue * Rate1);
                }
            }
            //  double Rate = Double.Parse(parts["RateValue"]);
            //   return LiveValue * Rate1;
        }