Exemplo n.º 1
0
        // ************************************************************
        // METHODS -- GET DATA
        // ************************************************************

        public myFrame GetEODPrices(HistoricalDataRequest myRequest)
        {
            // Check local database
            myFrame localData = Get_FromLocalDatabase(myRequest);


            // CASE A : NO DATA PRESENT IN LOCAL DB
            if (localData.IsEmpty() == true)
            {
                // 1. Fetch the data from external sources
                localData = Get_FromExternalSource(myRequest);

                // 2. Perform some checks
                // @TODO : checks needed

                // 3. Map the local DB
                string database = MapDatabase(myRequest.id);
                string table    = MapTable(myRequest.id);

                // 4. Assign to local DB
                myConnectorHelper.SetData(myRequest.id, database, table, localData);

                // 5. Return the data
                return(localData);
            }



            // CASE B : DATA FOUND
            else
            {
                // Check data for completeness (start date included in local data)
                bool startDatePresent = (myRequest.startDate >= localData.startDate);

                // Check data for completeness (end date included in local data)
                bool endDatePresent = (myRequest.endDate <= localData.endDate);

                // Which leads to 4 possible cases...

                // CASE B-1 : Time period covered by local data
                if (startDatePresent && endDatePresent)
                {
                    return(localData);
                }

                // CASE B-2 : Start Date Covered but not end date
                else if (startDatePresent && !endDatePresent)
                {
                    myFrame endData = UpdateData(myRequest, localData.endDate.AddDays(1), myRequest.endDate);

                    // Merge with existing data
                    localData.Union(endData);

                    // Return
                    return(localData);
                }

                // CASE B-3 : Start Date not covered but end date present
                else if (!startDatePresent && endDatePresent) // ----------------> Verified
                {
                    // Update local database
                    myFrame startData = UpdateData(myRequest, myRequest.startDate, localData.startDate.AddDays(-1));

                    // Merge with existing data
                    localData.Union(startData);

                    // Return
                    return(localData);
                }

                // CASE B-4 : Both ends not covered
                else
                {
                    //myFrame startData = UpdateData(myRequest, localData.startDate, myRequest.startDate.AddDays(-1));
                    myFrame startData = UpdateData(myRequest, myRequest.startDate, localData.startDate.AddDays(-1));
                    localData.Union(startData);

                    myFrame endData = UpdateData(myRequest, myRequest.endDate.AddDays(1), localData.endDate);
                    localData.Union(endData);

                    return(localData);
                }
            }
        }