示例#1
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());
        }
示例#2
0
        public void UpdateDisplay(SiidDevice Rule)
        {
            try
            {
                var parts = HttpUtility.ParseQueryString(Rule.Device.get_PlugExtraData_Get(Instance.host).GetNamed("SSIDKey").ToString());

                //Do the calculator string parse to get the new value
                string RawNumberString     = GeneralHelperFunctions.GetValues(Instance, parts["ScratchPadString"]);
                double RawCalculatedString = CalculateString(RawNumberString); //Raw meter read
                double CalculatedString    = 0;                                //difference betweenold and new values
                double RatedString         = 0;                                //difference multiplied by the rate



                if (bool.Parse(parts["IsAccumulator"]))
                {
                    CalculatedString = RawCalculatedString - Double.Parse(parts["OldValue"]);
                }

                //Raw value is before rate
                //So to get the pre-rate value from another scratchpad rule do $(ruleID)
                //To get the post rate value do #(ruleID)

                try
                {
                    //In a meter setting the Calculated String is the raw meter read. Now we multiply it by the rate (because the output should be the cost of the meter)

                    //SO Time for some odd hardcoding.

                    //Every meter uses rate Unless it's an indoor water meter or an outdoor water meter.  We will check for those and apply the tiered rates if so.
                    //In the future we may want to genealize this
                    String Name = Rule.Device.get_Name(Instance.host).ToLower();
                    if (Name.Contains("water") && Name.Contains("meter") && (Name.Contains("indoor") || Name.Contains("outdoor")))
                    {
                        RatedString = TieredRate(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"]);
                        }

                        //round calculated string and rated string to nearest hundreths place
                        RatedString = CalculatedString * Rate;
                    }
                }
                catch (Exception e)
                {
                    Instance.hspi.Log("Problem rendering scratchpad rule " + e.Message, 2);
                }


                //processed value is after rate



                //If the reset time was too soon, set CalculatedString to be 0



                if (bool.Parse(parts["IsAccumulator"]) && DateTime.Now.AddHours(-1).Subtract(DateTime.Parse(parts["DateOfLastReset"])).TotalSeconds < 45)  //If the reset was less than 45 seconds ago, display 0 as the scratchpad value
                {
                    CalculatedString = 0;
                    RatedString      = 0;
                }

                RatedString         = Math.Round(RatedString * 1000) / 1000;
                CalculatedString    = Math.Round(CalculatedString * 1000) / 1000;
                RawCalculatedString = Math.Round(RawCalculatedString * 1000) / 1000;

                string ValueString = String.Format(parts["DisplayString"], RatedString);

                Instance.host.SetDeviceString(Rule.Ref, ValueString, true);
                Instance.host.SetDeviceValueByRef(Rule.Ref, CalculatedString, true);

                Rule.LoadExtraData();
                Rule.UpdateExtraDataNoCall("NewValue", "" + RawCalculatedString.ToString()); //Newest meter read
                Rule.UpdateExtraDataNoCall("RawValue", "" + CalculatedString);               //Raw meter read for this month
                Rule.UpdateExtraDataNoCall("ProcessedValue", "" + RatedString);              //Raw meter read multiplied by rate information
                Rule.UpdateExtraDataNoCall("CurrentTime", "" + DateTime.Now.ToString());
                Rule.UpdateExtraDataNoCall("DisplayedValue", "" + ValueString);              //the ProcessedValue displayed on the meter
                Rule.SaveExtraData();

                // EDO.RemoveNamed("SSIDKey");
                //  EDO.AddNamed("SSIDKey", parts.ToString());

                parts = HttpUtility.ParseQueryString(Rule.Device.get_PlugExtraData_Get(Instance.host).GetNamed("SSIDKey").ToString());

                string userNote = Rule.Device.get_UserNote(Instance.host);
                userNote  = userNote.Split("PLUGIN EXTRA DATA:".ToCharArray())[0];
                userNote += "PLUGIN EXTRA DATA:" + parts.ToString();
                Rule.Device.set_UserNote(Instance.host, userNote);

                Rule.Device.set_PlugExtraData_Set(Instance.host, Rule.Extra);
            }
            catch (Exception e)
            {
                Instance.hspi.Log("Problem updating scratchpad display " + e.Message, 2);
            }

            //Check if rule is an accumulator, if so do NewValue - OldValue

            //String Format the value, put results in display

            doLiveRule(Rule);
        }