public WasteTypeFilter(WasteTypeFilter.Type wasteType) { this.HazardousWasteCountry = false; this.HazardousWasteTransboundary = false; this.NonHazardousWaste = false; switch (wasteType) { case WasteTypeFilter.Type.HazardousCountry: { HazardousWasteCountry = true; break; } case WasteTypeFilter.Type.HazardousTransboundary: { HazardousWasteTransboundary = true; break; } case WasteTypeFilter.Type.NonHazardous: { NonHazardousWaste = true; break; } } }
private static Expression <Func <WASTETRANSFER, bool> > getLambdaExpression(WasteTypeFilter.Type wasteType) { ParameterExpression param = Expression.Parameter(typeof(WASTETRANSFER), "s"); Expression exp = LinqExpressionBuilder.GetLinqExpressionWasteTransferType(wasteType, param, false); Expression <Func <WASTETRANSFER, bool> > lambda = Expression.Lambda <Func <WASTETRANSFER, bool> >(exp, param); return(lambda); }
public void Populate(int facilityid, WasteTypeFilter.Type wasteType, bool hasConfidentialInformation) { this.divConfidentialityInformation.Visible = hasConfidentialInformation; this.divNoConfidentialityInformation.Visible = !hasConfidentialInformation; this.lvConfidentiality.Visible = true; this.lvConfidentiality.DataSource = WasteTransferTrend.GetConfidentiality(facilityid, wasteType); this.lvConfidentiality.DataBind(); }
public WasteTransfer(int year, int facilities, WasteTypeFilter.Type wasteType, double?total, double?recovery, double?disposal, double?unspec) : this(year, wasteType) { this.Facilities = facilities; this.QuantityTotal = total; this.QuantityRecovery = recovery; this.QuantityDisposal = disposal; this.QuantityUnspec = unspec; this.QuantityUnit = CODE_TNE; //waste is always reported in tonnes }
/// <summary> /// updateTimeSeries /// </summary> private void updateCompareChart(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType) { CurrentWasteType = wasteType; // view everything, user may select other years to compare dataFound(true); // init year combo boxes int year1 = this.ucYearCompare.Year1; int year2 = this.ucYearCompare.Year2; // get compare result compare char TimeSeriesClasses.ComparisonWasteTransfer result = WasteTransferTrend.GetComparisonTimeSeries(filter, year1, year2, wasteType); bool foundData = (result.TotalFrom != null || result.TotalTo != null); if (foundData) { dataFound(true); Color[] colors = new Color[] { Global.ColorWasteTotal, Global.ColorWasteTotal }; ChartHatchStyle[] hatchStyles = new ChartHatchStyle[] { Global.HatchStyleBothYears, Global.HatchStyleTotal }; string[] legendTexts = new string[] { Resources.GetGlobal("Common", "FacilitiesBothYears"), Resources.GetGlobal("Common", "AllFacilities") }; this.ucStackColumnCompare.Initialize(colors.Length, StackColumnType.Comparison, CODE_TNE, colors, hatchStyles, legendTexts); // from and to bar TimeSeriesUtils.BarData dataFrom = new TimeSeriesUtils.BarData { Year = result.YearFrom, Values = new double?[] { TimeSeriesUtils.RangeValue(result.BothTotalFrom), TimeSeriesUtils.RangeValue(result.TotalFrom) - TimeSeriesUtils.RangeValue(result.BothTotalFrom) }, }; TimeSeriesUtils.BarData dataTo = new TimeSeriesUtils.BarData { Year = result.YearTo, Values = new double?[] { TimeSeriesUtils.RangeValue(result.BothTotalTo), TimeSeriesUtils.RangeValue(result.TotalTo) - TimeSeriesUtils.RangeValue(result.BothTotalTo) }, }; // from and to bar this.ucStackColumnCompare.Add(new List <TimeSeriesUtils.BarData>() { dataFrom, dataTo }); // update sinle table updateTable(result); } else { dataFound(false); } }
/// <summary> /// Update flash graph /// </summary> /// <param name="filter"></param> /// <param name="value">Chart data</param> /// <param name="chartLabel">Passed to flash charts.</param> private void updateGraph(WasteTransferSearchFilter filter, WasteTypeFilter.Type wasteType) { List <WasteTransfers.AreaComparison> result = null; string chartLabel = String.Empty; if (wasteType.Equals(WasteTypeFilter.Type.NonHazardous)) // Non Hazardous waste { if (ViewState[DATA_NONHW] != null) { result = ViewState[DATA_NONHW] as List <WasteTransfers.AreaComparison>; } else { result = WasteTransfers.GetAreaComparison(filter, WasteTypeFilter.Type.NonHazardous); translateArea(filter.AreaFilter, result); ViewState[DATA_NONHW] = result; } chartLabel = Resources.GetGlobal("Common", "NoHazardouswaste"); } else if (wasteType.Equals(WasteTypeFilter.Type.HazardousCountry)) // hazardous within country (Hazardous waste, domestic) { if (ViewState[DATA_HWIC] != null) { result = ViewState[DATA_HWIC] as List <WasteTransfers.AreaComparison>; } else { result = WasteTransfers.GetAreaComparison(filter, WasteTypeFilter.Type.HazardousCountry); translateArea(filter.AreaFilter, result); ViewState[DATA_HWIC] = result; } chartLabel = Resources.GetGlobal("Common", "HazardouswasteWithinCountry"); } else if (wasteType.Equals(WasteTypeFilter.Type.HazardousTransboundary)) // Hazardous waste, transboundary { if (ViewState[DATA_HWOC] != null) { result = ViewState[DATA_HWOC] as List <WasteTransfers.AreaComparison>; } else { result = WasteTransfers.GetAreaComparison(filter, WasteTypeFilter.Type.HazardousTransboundary); translateArea(filter.AreaFilter, result); ViewState[DATA_HWOC] = result; } chartLabel = Resources.GetGlobal("Common", "HazardouswasteTransboundary"); } //add flash AddFlashCharts(result, chartLabel); }
/// <summary> /// returns a dictionary with sheet headers <key, value> for waste transfers time series search /// </summary> public static Dictionary <string, string> GetTsWasteTransfersSearchHeader( WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type currentWasteType, bool confidentialityAffected) { Dictionary <string, string> header = makeHeader(); addArea(header, filter.AreaFilter); addActivity(header, filter.ActivityFilter); addWasteType(header, currentWasteType); addConfidentiality(header, confidentialityAffected); return(header); }
/// <summary> /// getTimeSeriesData /// </summary> private List <TimeSeriesClasses.WasteTransfer> getTimeSeriesData(int facilityid, WasteTypeFilter.Type wasteType) { List <TimeSeriesClasses.WasteTransfer> data = null; // look in viewstate first data = ViewState[TIMESERIES_DATA] as List <TimeSeriesClasses.WasteTransfer>; // if no data in viewstate or id has changed, query db if ((data == null || data.Count() == 0)) { data = WasteTransferTrend.GetTimeSeries(facilityid, wasteType); ViewState[TIMESERIES_DATA] = data; } return(data); }
int IComparer <string> .Compare(string x, string y) { if (String.IsNullOrEmpty(x)) { return(-1); } if (y == null) { return(1); } WasteTypeFilter.Type type1 = (WasteTypeFilter.Type)EnumUtil.Parse(typeof(WasteTypeFilter.Type), x); WasteTypeFilter.Type type2 = (WasteTypeFilter.Type)EnumUtil.Parse(typeof(WasteTypeFilter.Type), y); return(type1.CompareTo(type2)); }
private void showContent(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType) { CurrentWasteType = wasteType; //examine if there exists any confidential data for the waste type given bool hasConfidentialInformationType = WasteTransferTrend.IsAffectedByConfidentiality(filter, wasteType); this.divConfidentialityInformation.Visible = hasConfidentialInformationType; this.divNoConfidentialityInformation.Visible = !hasConfidentialInformationType; if (hasConfidentialInformationType) { this.lvConfidentiality.DataSource = WasteTransferTrend.GetCountConfidentialFacilities(filter, wasteType); this.lvConfidentiality.DataBind(); } }
/// <summary> /// Search, fill data into summery /// </summary> public void Populate(int facilityReportId, int searchYear, WasteTypeFilter.Type waste) { FacilityBasic = Facility.GetFacilityBasic(facilityReportId); ViewState[FACILITY_SPECIAL] = facilityReportId; WasteType = waste; SearchYear = searchYear; // reset viewstate data ViewState[TIMESERIES_DATA] = null; showContent(TrendWasteContent.TimeSeries.ToString()); // set the year according to search. Waste does not inclucde EPER List <int> years = years = ListOfValues.ReportYears(false).ToList(); this.ucYearCompareSeries.Initialize(years, searchYear); }
/// <summary> /// /// </summary> public void Populate(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType) { SearchFilter = filter; var counts = WasteTransferTrend.GetCountFacilities(filter); this.ucWasteTypeSelector.PopulateRadioButtonList(filter.WasteTypeFilter, wasteType, counts); // check that any relases are selected if (!filter.WasteTypeFilter.HazardousWasteCountry && !filter.WasteTypeFilter.HazardousWasteTransboundary && !filter.WasteTypeFilter.NonHazardousWaste) { dataFound(false); return; } }
/// <summary> /// Returns true if the filter includes the waste type given. /// For type "Hazardous" true will be returned as soon as one of the hazardous types are included /// </summary> public bool InludesWasteType(WasteTypeFilter.Type wasteType) { switch (wasteType) { case Type.NonHazardous: return(NonHazardousWaste); case Type.HazardousCountry: return(HazardousWasteCountry); case Type.HazardousTransboundary: return(HazardousWasteTransboundary); case Type.Hazardous: return(HazardousWasteCountry || HazardousWasteTransboundary); default: throw new ArgumentOutOfRangeException("Unknown waste type"); } }
/// <summary> /// Select the correct unspecified quantity dependend on the waste type /// </summary> public static Func <WASTETRANSFER, double?> QuantityUnspec(WasteTypeFilter.Type wasteType) { Expression <Func <WASTETRANSFER, double?> > func; switch (wasteType) { case WasteTypeFilter.Type.NonHazardous: func = s => s.QuantityUnspecNONHW; break; case WasteTypeFilter.Type.HazardousCountry: func = s => s.QuantityUnspecHWIC; break; case WasteTypeFilter.Type.HazardousTransboundary: func = s => s.QuantityUnspecHWOC; break; default: throw new ArgumentOutOfRangeException("wasteType", "Illegal waste type"); } return(func.Compile()); }
/// <summary> /// Select the correct ConfidentialIndicatordependend on the waste type /// </summary> public static Func <WASTETRANSFER, bool> ConfidentialityIndicatorQuantity(WasteTypeFilter.Type wasteType) { Expression <Func <WASTETRANSFER, bool> > func; switch (wasteType) { case WasteTypeFilter.Type.NonHazardous: func = s => (bool)s.ConfidentialIndicatorNONHW && s.QuantityTotalNONHW.Equals(null); break; case WasteTypeFilter.Type.HazardousCountry: func = s => (bool)s.ConfidentialIndicatorHWIC && s.QuantityTotalHWIC.Equals(null); break; case WasteTypeFilter.Type.HazardousTransboundary: func = s => (bool)s.ConfidentialIndicatorHWOC && s.QuantityTotalHWOC.Equals(null); break; default: throw new ArgumentOutOfRangeException("wasteType", String.Format("Illegal waste type:{0}", wasteType.ToString())); } return(func.Compile()); }
/// <summary> /// Select the correct total quantity dependend on the waste type /// </summary> public static Func <WASTETRANSFER, double?> QuantityTotal(WasteTypeFilter.Type wasteType) { Expression <Func <WASTETRANSFER, double?> > func; switch (wasteType) { case WasteTypeFilter.Type.NonHazardous: func = z => z.QuantityTotalNONHW; break; case WasteTypeFilter.Type.HazardousCountry: func = z => z.QuantityTotalHWIC; break; case WasteTypeFilter.Type.HazardousTransboundary: func = z => z.QuantityTotalHWOC; break; default: throw new ArgumentOutOfRangeException("wasteType", String.Format("Illegal waste type:{0}", wasteType.ToString())); } return(func.Compile()); }
/// <summary> /// populate radiubutton list, select type /// </summary> public void PopulateRadioButtonList( WasteTypeFilter filter, WasteTypeFilter.Type selected, WasteTransfers.FacilityCountObject counts) { addButtons(filter, counts); string value = getRadioButtonValue(selected); if (filter.InludesWasteType(selected) && this.rblWasteTypeSelector.Items.FindByValue(value) != null) { rblWasteTypeSelector.SelectedValue = value; OnWasteTypeSelected(new WasteTypeSelectedEventArgs(value)); } else { // waste type not supported by this control, select default if (this.rblWasteTypeSelector.Items.Count > 0) { rblWasteTypeSelector.SelectedIndex = 0; OnWasteTypeSelected(new WasteTypeSelectedEventArgs(rblWasteTypeSelector.SelectedValue)); } } }
/// <summary> /// return true if confidentiality might effect result /// </summary> public static bool IsAffectedByConfidentiality(int facilityID, WasteTypeFilter.Type wasteType) { var confidentialData = GetTimeSeries(facilityID, wasteType); return(confidentialData.Any()); }
public WasteTransfer(int year, int facilities, WasteTypeFilter.Type wasteType, double?total, double?recovery, double?disposal, double?unspec, int countries) : this(year, facilities, wasteType, total, recovery, disposal, unspec) { this.Countries = countries; }
private string getRadioButtonValue(WasteTypeFilter.Type wasteType) { return(EnumUtil.GetStringValue(wasteType)); }
/// <summary> /// Constructor for quanitiy, waste /// </summary> public WasteTransfer(int year, WasteTypeFilter.Type wasteType) { this.Year = year; this.WasteType = wasteType; }
/// <summary> /// returns a dictionary with sheet headers <key, value> for facility details /// </summary> public static Dictionary <string, string> GetFacilityDetailWasteTrendHeader(Facility.FacilityBasic facilityBasic, WasteTypeFilter.Type wasteType) { Dictionary <string, string> header = new Dictionary <string, string>(); addFacilityName(header, facilityBasic); addFacilityAddress(header, facilityBasic); addFacilityCountry(header, facilityBasic); addWasteType(header, wasteType); return(header); }
// --------------------------------------------------------------------------------------------------- // Comparison // --------------------------------------------------------------------------------------------------- #region comparison /// <summary> /// GetComparisonTimeSeries /// </summary> public static TimeSeriesClasses.ComparisonWasteTransfer GetComparisonTimeSeries(WasteTransferTimeSeriesFilter filter, int yearFrom, int yearTo, WasteTypeFilter.Type wasteType) { // Create lambda with pollutant release filter Expression <Func <WASTETRANSFER, bool> > lambda = getLambdaExpression(filter, wasteType); DataClassesWasteTransferDataContext db = new DataClassesWasteTransferDataContext(); // group by reporting year, get from and to data IQueryable <IGrouping <int, WASTETRANSFER> > groupFrom = db.WASTETRANSFERs.Where(lambda).Where(p => p.ReportingYear == yearFrom).GroupBy(p => p.ReportingYear); IQueryable <IGrouping <int, WASTETRANSFER> > groupTo = db.WASTETRANSFERs.Where(lambda).Where(p => p.ReportingYear == yearTo).GroupBy(p => p.ReportingYear); // Facility IDs when year is 'yearTo' var vTo = db.WASTETRANSFERs.Where(lambda).Where(p => p.ReportingYear == yearTo).Select(p => p.FacilityID).Distinct(); IQueryable <IGrouping <int, WASTETRANSFER> > groupDataFromBoth = db.WASTETRANSFERs.Where(lambda).Where(p => p.ReportingYear == yearFrom && vTo.Contains(p.FacilityID)).GroupBy(p => p.ReportingYear); // Facility IDs when year is 'yearFrom' var vFrom = db.WASTETRANSFERs.Where(lambda).Where(p => p.ReportingYear == yearFrom).Select(p => p.FacilityID).Distinct(); IQueryable <IGrouping <int, WASTETRANSFER> > groupDataToBoth = db.WASTETRANSFERs.Where(lambda).Where(p => p.ReportingYear == yearTo && vFrom.Contains(p.FacilityID)).GroupBy(p => p.ReportingYear); // result lists IEnumerable <TimeSeriesClasses.TsWasteCompare> dataFrom = null, dataTo = null; IEnumerable <TimeSeriesClasses.TsWasteCompare> dataFromBoth = null, dataToBoth = null; switch (wasteType) { case WasteTypeFilter.Type.HazardousCountry: dataFrom = groupFrom.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWIC), x.Sum(p => p.QuantityRecoveryHWIC), x.Sum(p => p.QuantityDisposalHWIC), x.Sum(p => p.QuantityUnspecHWIC))); dataTo = groupTo.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWIC), x.Sum(p => p.QuantityRecoveryHWIC), x.Sum(p => p.QuantityDisposalHWIC), x.Sum(p => p.QuantityUnspecHWIC))); dataFromBoth = groupDataFromBoth.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWIC), x.Sum(p => p.QuantityRecoveryHWIC), x.Sum(p => p.QuantityDisposalHWIC), x.Sum(p => p.QuantityUnspecHWIC))); dataToBoth = groupDataToBoth.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWIC), x.Sum(p => p.QuantityRecoveryHWIC), x.Sum(p => p.QuantityDisposalHWIC), x.Sum(p => p.QuantityUnspecHWIC))); break; case WasteTypeFilter.Type.HazardousTransboundary: dataFrom = groupFrom.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWOC), x.Sum(p => p.QuantityRecoveryHWOC), x.Sum(p => p.QuantityDisposalHWOC), x.Sum(p => p.QuantityUnspecHWOC))); dataTo = groupTo.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWOC), x.Sum(p => p.QuantityRecoveryHWOC), x.Sum(p => p.QuantityDisposalHWOC), x.Sum(p => p.QuantityUnspecHWOC))); dataFromBoth = groupDataFromBoth.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWOC), x.Sum(p => p.QuantityRecoveryHWOC), x.Sum(p => p.QuantityDisposalHWOC), x.Sum(p => p.QuantityUnspecHWOC))); dataToBoth = groupDataToBoth.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalHWOC), x.Sum(p => p.QuantityRecoveryHWOC), x.Sum(p => p.QuantityDisposalHWOC), x.Sum(p => p.QuantityUnspecHWOC))); break; case WasteTypeFilter.Type.NonHazardous: dataFrom = groupFrom.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalNONHW), x.Sum(p => p.QuantityRecoveryNONHW), x.Sum(p => p.QuantityDisposalNONHW), x.Sum(p => p.QuantityUnspecNONHW))); dataTo = groupTo.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalNONHW), x.Sum(p => p.QuantityRecoveryNONHW), x.Sum(p => p.QuantityDisposalNONHW), x.Sum(p => p.QuantityUnspecNONHW))); dataFromBoth = groupDataFromBoth.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalNONHW), x.Sum(p => p.QuantityRecoveryNONHW), x.Sum(p => p.QuantityDisposalNONHW), x.Sum(p => p.QuantityUnspecNONHW))); dataToBoth = groupDataToBoth.Select(x => new TimeSeriesClasses.TsWasteCompare(x.Count(), x.Sum(p => p.QuantityTotalNONHW), x.Sum(p => p.QuantityRecoveryNONHW), x.Sum(p => p.QuantityDisposalNONHW), x.Sum(p => p.QuantityUnspecNONHW))); break; default: return(null); } TimeSeriesClasses.ComparisonWasteTransfer result = new TimeSeriesClasses.ComparisonWasteTransfer(yearFrom, yearTo); var res = dataFrom.SingleOrDefault(); if (res != null) { result.SetFrom(res.Count, res.Quantity, res.Recovery, res.Disposal, res.Unspecified); } res = dataTo.SingleOrDefault(); if (res != null) { result.SetTo(res.Count, res.Quantity, res.Recovery, res.Disposal, res.Unspecified); } res = dataFromBoth.SingleOrDefault(); if (res != null) { result.SetBothFrom(res.Count, res.Quantity, res.Recovery, res.Disposal, res.Unspecified); } res = dataToBoth.SingleOrDefault(); if (res != null) { result.SetBothTo(res.Count, res.Quantity, res.Recovery, res.Disposal, res.Unspecified); } return(result); }
/// <summary> /// get waste transfers for a specific facility report and wste type /// </summary> public static IEnumerable <FACILITYDETAIL_WASTETRANSFER> GetWasteTransfers(int reportID, WasteTypeFilter.Type type) { string wasteType = EnumUtil.GetStringValue(type); DataClassesFacilityDataContext db = getDataContext(); IEnumerable <FACILITYDETAIL_WASTETRANSFER> data = db.FACILITYDETAIL_WASTETRANSFERs.Where(c => c.FacilityReportID == reportID && c.WasteTypeCode.Equals(wasteType)); return(data); }
/// <summary> /// return timeseries /// </summary> public static List <TimeSeriesClasses.WasteTransfer> GetTimeSeries(int facilityID, WasteTypeFilter.Type wasteType) { DataClassesWasteTransferDataContext db = getDataContext(); //table has only one row per facility per year with aggregated data. IEnumerable <TimeSeriesClasses.WasteTransfer> data = db.WASTETRANSFERs.Where(s => s.FacilityID == facilityID) .OrderBy(s => s.ReportingYear) .Select(s => new TimeSeriesClasses.WasteTransfer( s.ReportingYear, 1, wasteType, LinqFunctionsWaste.QuantityTotal(wasteType)(s), LinqFunctionsWaste.QuantityRecovery(wasteType)(s), LinqFunctionsWaste.QuantityDisposal(wasteType)(s), LinqFunctionsWaste.QuantityUnspec(wasteType)(s) )); return(data.ToList()); }
// --------------------------------------------------------------------------------------------------- // Time series // --------------------------------------------------------------------------------------------------- #region timeseries /// <summary> /// return timeseries /// </summary> public static List <TimeSeriesClasses.WasteTransfer> GetTimeSeries(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wastetype) { DataClassesWasteTransferDataContext db = getDataContext(); // apply filter Expression <Func <WASTETRANSFER, bool> > lambda = getLambdaExpression(filter, wastetype); // get data and group by year (which get assigned to x.Key by link) IQueryable <IGrouping <int, WASTETRANSFER> > group = db.WASTETRANSFERs.Where(lambda).GroupBy(p => p.ReportingYear).OrderBy(p => p.Key); // lookup wastetype. Table has only one row per faciltiy report IEnumerable <TimeSeriesClasses.WasteTransfer> data = null; switch (wastetype) { case WasteTypeFilter.Type.HazardousCountry: data = group.Select(x => new TimeSeriesClasses.WasteTransfer(x.Key, x.Count(), WasteTypeFilter.Type.HazardousCountry, x.Sum(p => p.QuantityTotalHWIC), x.Sum(p => p.QuantityRecoveryHWIC), x.Sum(p => p.QuantityDisposalHWIC), x.Sum(p => p.QuantityUnspecHWIC))); break; case WasteTypeFilter.Type.HazardousTransboundary: data = group.Select(x => new TimeSeriesClasses.WasteTransfer(x.Key, x.Count(), WasteTypeFilter.Type.HazardousTransboundary, x.Sum(p => p.QuantityTotalHWOC), x.Sum(p => p.QuantityRecoveryHWOC), x.Sum(p => p.QuantityDisposalHWOC), x.Sum(p => p.QuantityUnspecHWOC))); break; case WasteTypeFilter.Type.NonHazardous: data = group.Select(x => new TimeSeriesClasses.WasteTransfer(x.Key, x.Count(), WasteTypeFilter.Type.NonHazardous, x.Sum(p => p.QuantityTotalNONHW), x.Sum(p => p.QuantityRecoveryNONHW), x.Sum(p => p.QuantityDisposalNONHW), x.Sum(p => p.QuantityUnspecNONHW))); break; default: throw new ArgumentOutOfRangeException("wastetype", String.Format("Illegal wastetype: {0}", wastetype.ToString())); } //add information about no. of reporting countries IEnumerable <Facility.ReportingCountries> years = Facility.GetReportingCountries(filter.AreaFilter).ToList(); IEnumerable <TimeSeriesClasses.WasteTransfer> res = from l in data.ToList() join r in years on l.Year equals r.Year select new TimeSeriesClasses.WasteTransfer( l.Year, l.Facilities, l.WasteType, l.QuantityTotal, l.QuantityRecovery, l.QuantityDisposal, l.QuantityUnspec, r.Countries); return(res.OrderBy(p => p.Year).ToList()); }
private static Expression <Func <WASTETRANSFER_CONFIDENTIAL, bool> > getLambdaExpressionConfidential(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType) { Expression <Func <WASTETRANSFER_CONFIDENTIAL, bool> > lambda = getLambdaExpressionConfidential(filter); ParameterExpression param = lambda.Parameters[0]; //Apply waste type Expression expType = LinqExpressionBuilder.GetLinqExpressionWasteTransferType(wasteType, param, true); Expression exp = LinqExpressionBuilder.CombineAnd(lambda.Body, expType); lambda = Expression.Lambda <Func <WASTETRANSFER_CONFIDENTIAL, bool> >(exp, param); return(lambda); }
// --------------------------------------------------------------------------------------------------- // confidentiality // --------------------------------------------------------------------------------------------------- #region Confidentiality public static IEnumerable <TimeSeriesClasses.ConfidentialityWaste> GetConfidentiality(int facilityId, WasteTypeFilter.Type wasteType) { DataClassesWasteTransferDataContext db = getDataContext(); // apply filter Expression <Func <WASTETRANSFER, bool> > lambda = getLambdaExpression(wasteType); //table have only one record per facility, so no aggregation is needed. IEnumerable <TimeSeriesClasses.ConfidentialityWaste> data = db.WASTETRANSFERs.Where(lambda) .Where(v => v.FacilityID == facilityId) .OrderBy(v => v.ReportingYear) .Select(v => new TimeSeriesClasses.ConfidentialityWaste { Year = v.ReportingYear, CountTotal = 1, CountConfTotal = Convert.ToInt32(LinqFunctionsWaste.ConfidentialityIndicator(wasteType)(v)), CountConfQuantity = Convert.ToInt32(LinqFunctionsWaste.ConfidentialityIndicatorQuantity(wasteType)(v)) }); return(data); }
public static List <TimeSeriesClasses.ConfidentialityWaste> GetCountConfidentialFacilities(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType) { DataClassesWasteTransferDataContext db = getDataContext(); Expression <Func <WASTETRANSFER_CONFIDENTIAL, bool> > lambda = getLambdaExpressionConfidential(filter, wasteType); //count all confidential claims //table has one row per facility per wastetype so distinct is needed List <TimeSeriesClasses.ConfidentialityWaste> confidential = db.WASTETRANSFER_CONFIDENTIALs.Where(lambda) .GroupBy(v => v.ReportingYear) .OrderBy(v => v.Key) .Select(v => new TimeSeriesClasses.ConfidentialityWaste { Year = v.Key, CountConfTotal = v.Select(x => x.FacilityReportID).Distinct().Count(), CountConfQuantity = v.Where(x => (bool)x.ConfidentialityOnQuantity).Select(x => x.FacilityReportID).Distinct().Count(), CountConfTreatment = v.Where(x => (bool)x.ConfidentialityOnTreatmant).Select(x => x.FacilityReportID).Distinct().Count() }).ToList(); if (confidential.Count() > 0) { List <TimeSeriesClasses.WasteTransfer> all = GetTimeSeries(filter, wasteType); foreach (TimeSeriesClasses.WasteTransfer wt in all) { TimeSeriesClasses.ConfidentialityWaste conf = confidential.SingleOrDefault(c => c.Year.Equals(wt.Year)); if (conf != null) { conf.CountTotal = wt.Facilities; } else { confidential.Add(new TimeSeriesClasses.ConfidentialityWaste { Year = wt.Year, CountTotal = wt.Facilities }); } } return(confidential.OrderBy(c => c.Year).ToList()); } return(new List <TimeSeriesClasses.ConfidentialityWaste>()); }
/// <summary> /// return true if confidentiality might effect result /// </summary> public static bool IsAffectedByConfidentiality(WasteTransferTimeSeriesFilter filter, WasteTypeFilter.Type wasteType) { Expression <Func <WASTETRANSFER_CONFIDENTIAL, bool> > lambda = getLambdaExpressionConfidential(filter, wasteType); DataClassesWasteTransferDataContext db = getDataContext(); return(db.WASTETRANSFER_CONFIDENTIALs.Any(lambda)); }