예제 #1
0
        /// <summary>
        /// Generate a feed from CSV files (from a spreadsheet).
        /// </summary>
        /// <param name="fundingPeriodStartYear">Optional - </param>
        /// <param name="fundingPeriodEndYear">Optional - </param>
        /// <param name="fundingPeriodCodes">Optional - The period codes to limit to (e.g. AY1920).</param>
        /// <param name="organisationGroupIdentifiers">Optional - The group identifiers to limit by (e.g. UKPRN 12345678).</param>
        /// <param name="organisationGroupTypes">Optional - The group types to limit to (e.g. Region, LocalAuthority).</param>
        /// <param name="organisationIdentifiers">Optional - The organisation identifiers to limit to (e.g. UKPRN 12345678).</param>
        /// <param name="organisationTypes">Optional - The organisation types to return.</param>
        /// <param name="variationReasons">Optional - Filter to only organisations with these variation reasons types</param>
        /// <param name="ukprns">Optional - Only get these UKPRNs back.</param>
        /// <param name="groupingReasons">Optional - The grouping reasons we want to get back (e.g. Information and/or Payment).</param>
        /// <param name="statuses">Optional - The status of the funding (e.g. Released).</param>
        /// <param name="minStatusChangeDate">Optional - Only get records back that were changed after this date.</param>
        /// <param name="fundingLineTypes">Optional - limit the types of lines we want to get back (e.g. Information and/or Payment).</param>
        /// <param name="templateLineIds">Optional - Filter the lines to these ids only.</param>
        /// <returns>An array of FeedResponseContentModel objects./returns>
        public static FeedResponseContentModel[] GenerateFeed(int?fundingPeriodStartYear, int?fundingPeriodEndYear,
                                                              string[] fundingPeriodCodes, OrganisationIdentifier[] organisationGroupIdentifiers, OrganisationType[] organisationGroupTypes,
                                                              OrganisationIdentifier[] organisationIdentifiers, OrganisationType[] organisationTypes, VariationReason[] variationReasons,
                                                              string[] ukprns, GroupingReason[] groupingReasons, FundingStatus[] statuses, DateTime?minStatusChangeDate,
                                                              FundingLineType[] fundingLineTypes, string[] templateLineIds)
        {
            var totalList = new List <FeedResponseContentModel>();

            // Check period dates
            if ((fundingPeriodStartYear != null && fundingPeriodStartYear != 2019) ||
                (fundingPeriodEndYear != null && fundingPeriodEndYear != 2020))
            {
                return(totalList.ToArray());
            }

            // Check period codes
            if (fundingPeriodCodes?.Any() == true && fundingPeriodCodes?.Contains("AY1920") == false)
            {
                return(totalList.ToArray());
            }

            // Check statuses
            if (statuses?.Any() == true && !statuses.Contains(FundingStatus.Released))
            {
                return(totalList.ToArray());
            }

            // Check feed cut off date
            if (minStatusChangeDate != null && minStatusChangeDate.Value > new DateTime(2019, 3, 1))
            {
                return(totalList.ToArray());
            }

            // If we only want information type, we are out of luck
            if (groupingReasons?.Any() == true && groupingReasons?.Contains(GroupingReason.Payment) == false)
            {
                return(totalList.ToArray());
            }

            var fundingVersion  = "1-0";
            var templateVersion = "1.0";
            var schemaVersion   = "1.0";

            var ukOffset = new TimeSpan(0, 0, 0);

            var period = new FundingPeriod
            {
                Code      = "AY1920",
                Name      = "Academic year 2019-20",
                Type      = PeriodType.AcademicYear,
                StartDate = new DateTimeOffset(2019, 9, 1, 0, 0, 0, ukOffset),
                EndDate   = new DateTimeOffset(2020, 8, 31, 0, 0, 0, ukOffset)
            };

            var stream = new StreamWithTemplateVersion
            {
                Code            = "PESports",
                Name            = "PE + Sport Premium",
                TemplateVersion = templateVersion,
            };

            var processFile = new ProcessPesportsCsv();

            var financialYearPeriod1920 = new FundingPeriod
            {
                Code      = "FY1920",
                Name      = "Financial Year 2019-20",
                Type      = PeriodType.FinancialYear,
                StartDate = new DateTimeOffset(2019, 4, 1, 0, 0, 0, ukOffset),
                EndDate   = new DateTimeOffset(2020, 3, 30, 0, 0, 0, ukOffset)
            };

            var financialYearPeriod2021 = new FundingPeriod
            {
                Code      = "FY2021",
                Name      = "Financial Year 2020-21",
                Type      = PeriodType.FinancialYear,
                StartDate = new DateTimeOffset(2020, 4, 1, 0, 0, 0, ukOffset),
                EndDate   = new DateTimeOffset(2021, 3, 30, 0, 0, 0, ukOffset)
            };

            var providerTypes = new List <string>
            {
                "MaintainedSchools",
                "Academies",
                "NonMaintainedSpecialSchools"
            };

            foreach (var providerType in providerTypes)
            {
                if ((providerType == "MaintainedSchools" || providerType == "NonMaintainedSpecialSchools") &&
                    organisationGroupTypes?.Any() == true && organisationGroupTypes?.Contains(OrganisationType.Provider) == false)
                {
                    continue;
                }
                else if (providerType == "Academies" &&
                         organisationGroupTypes?.Any() == true && organisationGroupTypes?.Contains(OrganisationType.AcademyTrust) == false)
                {
                    continue;
                }

                var groupByLa = false;

                switch (providerType)
                {
                case "MaintainedSchools":
                    groupByLa = true;

                    break;
                }

                var orgGroups = processFile.GetOrgsOrOrgGroups($"{providerType}.csv", groupByLa);

                totalList.AddRange(ProcessOrgGroups(orgGroups, providerType, financialYearPeriod1920, financialYearPeriod2021, period, stream, schemaVersion, fundingVersion,
                                                    organisationGroupIdentifiers, organisationIdentifiers, organisationTypes, variationReasons, ukprns, fundingLineTypes, templateLineIds)
                                   );
            }

            return(totalList.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Get the provider funding from the spreadsheet
        /// </summary>
        /// <param name="id">The id to lookup.</param>
        /// <returns>A provider funding object.</returns>
        public static ProviderFunding GenerateProviderFunding(string id)
        {
            var idParts = id.Split('_');
            var code    = idParts[2].Replace("MOCKUKPRN", string.Empty);

            var ukOffset = new TimeSpan(0, 0, 0);

            var period = new FundingPeriod
            {
                Code      = "AY1920",
                Name      = "Academic year 2019-20",
                Type      = PeriodType.AcademicYear,
                StartDate = new DateTimeOffset(2019, 9, 1, 0, 0, 0, ukOffset),
                EndDate   = new DateTimeOffset(2020, 8, 31, 0, 0, 0, ukOffset)
            };

            var templateVersion = "1.0";

            var stream = new StreamWithTemplateVersion
            {
                Code            = "PESports",
                Name            = "PE + Sport Premium",
                TemplateVersion = templateVersion,
            };

            var financialYearPeriod1920 = new FundingPeriod
            {
                Code      = "FY1920",
                Name      = "Financial Year 2019-20",
                Type      = PeriodType.FinancialYear,
                StartDate = new DateTimeOffset(2019, 4, 1, 0, 0, 0, ukOffset),
                EndDate   = new DateTimeOffset(2020, 3, 30, 0, 0, 0, ukOffset)
            };

            var financialYearPeriod2021 = new FundingPeriod
            {
                Code      = "FY2021",
                Name      = "Financial Year 2020-21",
                Type      = PeriodType.FinancialYear,
                StartDate = new DateTimeOffset(2020, 4, 1, 0, 0, 0, ukOffset),
                EndDate   = new DateTimeOffset(2021, 3, 30, 0, 0, 0, ukOffset)
            };

            var processFile = new ProcessPesportsCsv();

            var orgGroups = new List <OrgGroup>();

            orgGroups.AddRange(processFile.GetOrgsOrOrgGroups("MaintainedSchools.csv", true));
            orgGroups.AddRange(processFile.GetOrgsOrOrgGroups("Academies.csv", false));
            orgGroups.AddRange(processFile.GetOrgsOrOrgGroups("MaintainedSchools.csv", false));

            foreach (var orgGroup in orgGroups)
            {
                foreach (var provider in orgGroup.Providers)
                {
                    if (provider.LaEstablishmentNo == code)
                    {
                        return(GetProviderFunding(provider, financialYearPeriod1920, financialYearPeriod2021, period, stream, orgGroup.Type, orgGroup.Code));
                    }
                }
            }

            return(null);
        }