Exemplo n.º 1
0
        //public double getkWhFromMeter(int meterId, string startDate, string endDate)
        //{
        //    Meter meter = mediator.DataManager.getMeter(meterId);
        //    List<Chunk> dataIn = mediator.convertReadingsToChunks(meter.Register.ToList());

        //    double kWh = mediator.apportionToDates(dataIn, startDate, endDate);
        //    return kWh;
        //}


        public List <Chunk> getDataFromMeterByInterval(int meterId, string startDate, string endDate, int intervalId, int dataTypeId)
        {
            Meter        meter  = mediator.DataManager.getMeter(meterId);
            List <Chunk> dataIn = new List <Chunk>();

            switch (dataTypeId)
            {
            case 1:         ///energy data
                dataIn = mediator.convertReadingsToChunks(meter.Register.ToList());
                break;

            case 2:         ///cost data
                dataIn = mediator.convertInvoicesToChunks(meter.Invoices.ToList());
                break;
            }

            DateTime start = Convert.ToDateTime(startDate);
            DateTime end   = Convert.ToDateTime(endDate);

            AppotionmentPeriod interval = (AppotionmentPeriod)intervalId;

            List <Chunk> result = mediator.apportionToPeriod(dataIn, start, end, interval);

            return(result);
        }
 public List<Chunk> setupDatedChunksForApportionToPeriod(
     [PexAssumeUnderTest]ApportionmentManager target,
     DateTime startDate,
     DateTime endDate,
     AppotionmentPeriod interval
     )
 {
     List<Chunk> result = target.setupDatedChunksForApportionToPeriod(startDate, endDate, interval);
     return result;
     // TODO: add assertions to method ApportionmentManagerTest.setupDatedChunksForApportionToPeriod(ApportionmentManager, DateTime, DateTime, AppotionmentPeriod)
 }
        public List <Chunk> setupDatedChunksForApportionToPeriod(
            [PexAssumeUnderTest] ApportionmentManager target,
            DateTime startDate,
            DateTime endDate,
            AppotionmentPeriod interval
            )
        {
            List <Chunk> result = target.setupDatedChunksForApportionToPeriod(startDate, endDate, interval);

            return(result);
            // TODO: add assertions to method ApportionmentManagerTest.setupDatedChunksForApportionToPeriod(ApportionmentManager, DateTime, DateTime, AppotionmentPeriod)
        }
 public List<Chunk> apportionToPeriod(
     [PexAssumeUnderTest]ApportionmentManager target,
     List<Chunk> dataIn,
     DateTime startDate,
     DateTime endDate,
     AppotionmentPeriod interval
     )
 {
     List<Chunk> result = target.apportionToPeriod(dataIn, startDate, endDate, interval);
     return result;
     // TODO: add assertions to method ApportionmentManagerTest.apportionToPeriod(ApportionmentManager, List`1<Chunk>, DateTime, DateTime, AppotionmentPeriod)
 }
        public List <Chunk> apportionToPeriod(
            [PexAssumeUnderTest] ApportionmentManager target,
            List <Chunk> dataIn,
            DateTime startDate,
            DateTime endDate,
            AppotionmentPeriod interval
            )
        {
            List <Chunk> result = target.apportionToPeriod(dataIn, startDate, endDate, interval);

            return(result);
            // TODO: add assertions to method ApportionmentManagerTest.apportionToPeriod(ApportionmentManager, List`1<Chunk>, DateTime, DateTime, AppotionmentPeriod)
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts meter readings / invoice costs into consumption between regular intervals.
        /// </summary>
        /// <param name="dataIn">List of date/double pairs that represent raw meter readings or invoices</param>
        /// <param name="startDate">start date of required apportioned consumption</param>
        /// <param name="endDate">end date of required apportioned consumption</param>
        /// <param name="interval">interval between required apportioned date/double pairs</param>
        /// <returns>Returns null if apportionment cannot be undertaken (not enough readings/invoices / no readings/invoices in specified time period)</returns>
        public List <Chunk> apportionToPeriod(List <Chunk> dataIn, DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
        {
            if (!canApportion(dataIn, startDate, endDate))
            {
                return(null);
            }

            else
            {
                ///create list of dated chunks with no consumptions, used to create the final results list
                List <Chunk> datedChunks = setupDatedChunksForApportionToPeriod(startDate, endDate, interval);

                ///do the actual apportioning of data
                return(apportion(datedChunks, dataIn));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates List[Chunk], with regular start and end dates for required intervals.  Amount = 0 for all Chunks.
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="interval"></param>
        /// <returns>List[Chunk] for required duration, each Chunk covering one interval.</returns>
        public List <Chunk> setupDatedChunksForApportionToPeriod(DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
        {
            ///calendar object used for adding days/months/years to start date
            System.Globalization.Calendar calendar = System.Globalization.CultureInfo.CurrentCulture.Calendar;

            ///set up apportionment requirements
            List <Chunk> datedChunks = new List <Chunk>();
            int          periodType  = (int)interval;

            ///i used to keep track of how many Chunks have already been created & adds appropriate no. of intervals to start date.
            int i = 0;

            ///create list of chunks with correct required start dates
            do
            {
                Chunk    chunk  = new Chunk();
                TimeSpan oneDay = new TimeSpan(1, 0, 0); ///one day timespan needed to calculate end dates

                switch (periodType)
                {
                case 1:     ///interval is daily
                    ///

                    chunk.StartDate = calendar.AddDays(startDate, i);
                    chunk.EndDate   = calendar.AddDays(chunk.StartDate, 1);
                    break;

                case 2:     ///interval is weekly
                    ///
                    chunk.StartDate = calendar.AddWeeks(startDate, i);
                    chunk.EndDate   = calendar.AddWeeks(chunk.StartDate, 1);
                    break;

                case 3:     ///interval is monthly
                    ///
                    chunk.StartDate = calendar.AddMonths(startDate, i);
                    chunk.EndDate   = calendar.AddMonths(chunk.StartDate, 1);
                    break;

                case 4:     ///interval is quarterly
                    ///
                    chunk.StartDate = calendar.AddMonths(startDate, 3 * i);
                    chunk.EndDate   = calendar.AddMonths(chunk.StartDate, 3 * 1);

                    break;

                case 5:     ///interval is annually
                    ///
                    chunk.StartDate = calendar.AddYears(startDate, i);
                    chunk.EndDate   = calendar.AddYears(chunk.StartDate, 1);
                    break;
                }

                ///take on day off each date date to avoid overlapping date ranges
                chunk.EndDate = chunk.EndDate.Subtract(oneDay);
                datedChunks.Add(chunk);
                i++;
            } while (datedChunks.ElementAt(i - 1).EndDate <= endDate);

            return(datedChunks);
        }
Exemplo n.º 8
0
 public List <Chunk> setupDatedChunksForApportionToPeriod(DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
 {
     apportionmentMgr = new ApportionmentManager();
     return(apportionmentMgr.setupDatedChunksForApportionToPeriod(startDate, endDate, interval));
 }
Exemplo n.º 9
0
 public List <Chunk> apportionToPeriod(List <Chunk> dataIn, DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
 {
     apportionmentMgr = new ApportionmentManager();
     return(apportionmentMgr.apportionToPeriod(dataIn, startDate, endDate, interval));
 }
Exemplo n.º 10
0
 public List<Chunk> apportionToPeriod(List<Chunk> dataIn, DateTime startDate, DateTime endDate,  AppotionmentPeriod interval)
 {
     apportionmentMgr = new ApportionmentManager();
     return apportionmentMgr.apportionToPeriod(dataIn, startDate, endDate, interval);
 }
Exemplo n.º 11
0
 public List<Chunk> setupDatedChunksForApportionToPeriod(DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
 {
     apportionmentMgr = new ApportionmentManager();
     return apportionmentMgr.setupDatedChunksForApportionToPeriod(startDate, endDate, interval);
 }
        /// <summary>
        /// Creates List[Chunk], with regular start and end dates for required intervals.  Amount = 0 for all Chunks.
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="interval"></param>
        /// <returns>List[Chunk] for required duration, each Chunk covering one interval.</returns>
        public List<Chunk> setupDatedChunksForApportionToPeriod(DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
        {
            ///calendar object used for adding days/months/years to start date
            System.Globalization.Calendar calendar = System.Globalization.CultureInfo.CurrentCulture.Calendar;

            ///set up apportionment requirements
            List<Chunk> datedChunks = new List<Chunk>();
            int periodType = (int)interval;

            ///i used to keep track of how many Chunks have already been created & adds appropriate no. of intervals to start date.
            int i = 0;

            ///create list of chunks with correct required start dates
            do
            {
                Chunk chunk = new Chunk();
                TimeSpan oneDay = new TimeSpan(1, 0, 0); ///one day timespan needed to calculate end dates

                switch (periodType)
                {

                    case 1: ///interval is daily
                        ///

                        chunk.StartDate = calendar.AddDays(startDate, i);
                        chunk.EndDate = calendar.AddDays(chunk.StartDate, 1);
                        break;

                    case 2: ///interval is weekly
                        ///
                        chunk.StartDate = calendar.AddWeeks(startDate, i);
                        chunk.EndDate = calendar.AddWeeks(chunk.StartDate, 1);
                        break;

                    case 3: ///interval is monthly
                        ///
                        chunk.StartDate = calendar.AddMonths(startDate, i);
                        chunk.EndDate = calendar.AddMonths(chunk.StartDate, 1);
                        break;

                    case 4: ///interval is quarterly
                        ///
                        chunk.StartDate = calendar.AddMonths(startDate, 3 * i);
                        chunk.EndDate = calendar.AddMonths(chunk.StartDate, 3 * 1);

                        break;

                    case 5: ///interval is annually
                        ///
                        chunk.StartDate = calendar.AddYears(startDate, i);
                        chunk.EndDate = calendar.AddYears(chunk.StartDate, 1);
                        break;

                }

                ///take on day off each date date to avoid overlapping date ranges
                chunk.EndDate = chunk.EndDate.Subtract(oneDay);
                datedChunks.Add(chunk);
                i++;

            } while (datedChunks.ElementAt(i - 1).EndDate <= endDate);

            return datedChunks;
        }
        /// <summary>
        /// Converts meter readings / invoice costs into consumption between regular intervals.
        /// </summary>
        /// <param name="dataIn">List of date/double pairs that represent raw meter readings or invoices</param>
        /// <param name="startDate">start date of required apportioned consumption</param>
        /// <param name="endDate">end date of required apportioned consumption</param>
        /// <param name="interval">interval between required apportioned date/double pairs</param>
        /// <returns>Returns null if apportionment cannot be undertaken (not enough readings/invoices / no readings/invoices in specified time period)</returns>
        public List<Chunk> apportionToPeriod(List<Chunk> dataIn, DateTime startDate, DateTime endDate, AppotionmentPeriod interval)
        {
            if (!canApportion(dataIn, startDate, endDate))
            {
                return null;
            }

            else
            {
                ///create list of dated chunks with no consumptions, used to create the final results list
                List<Chunk> datedChunks = setupDatedChunksForApportionToPeriod(startDate, endDate, interval);

                ///do the actual apportioning of data
                return apportion(datedChunks, dataIn);
            }
        }
Exemplo n.º 14
0
        public List <Chunk> getDataAtProperty(int propertyId, string startDate, string endDate, int intervalId, int dataTypeId)
        {
            Property property = mediator.DataManager.getProperty(propertyId);

            ///setup vairable for apportionment manager
            DateTime           start    = Convert.ToDateTime(startDate);
            DateTime           end      = Convert.ToDateTime(endDate);
            AppotionmentPeriod interval = (AppotionmentPeriod)intervalId;

            ///property apportioned consumption requires a list of sub-lists, each sub-list the result of interval apportion on that
            ///meter.  the final list returned is the sum of each chunk on the sub list. SO...

            ///create reference list for dates
            List <Chunk> datedChunks = mediator.setupDatedChunksForApportionToPeriod(start, end, interval);

            ///List<Chunk> datedChunks = mediator.getDataFromMeterByInterval(property.Meters.ElementAt(0).Id, startDate, endDate, intervalId, dataTypeId);

            ///create the containing master list, which will have one list for each meter
            List <List <Chunk> > masterList = new List <List <Chunk> >();

            ///add a new list for each meter, where the list is the result of apportioning the meter by interval
            foreach (Meter meter in property.Meters)
            {
                List <Chunk> apportionedData = mediator.getDataFromMeterByInterval(meter.Id, startDate, endDate, intervalId, dataTypeId);

                if (apportionedData != null)
                {
                    masterList.Add(apportionedData);
                }
            }

            ///create result list that will have one list of chunks
            List <Chunk> resultsList = new List <Chunk>();

            foreach (Chunk chunk in datedChunks)
            {
                Chunk newChunk = new Chunk()
                {
                    StartDate = chunk.StartDate,
                    EndDate   = chunk.EndDate
                };



                foreach (List <Chunk> subList in masterList)
                {
                    Chunk matchingChunk = subList.Find(chk => chk.StartDate == chunk.StartDate);

                    try
                    {
                        newChunk.Amount += matchingChunk.Amount;
                    }
                    catch
                    {
                        ///here there is no chunk on the subList at the required index
                        ///can proceed to the next chunk in datedChunks
                    }
                }

                resultsList.Add(newChunk);
            }

            return(resultsList);
        }