Ejemplo n.º 1
0
func (m *HistoricalValueEquation) GetValueEquationDocument(ctx *orm.DataContext, VEDQList []*ValueEquationDataQuality) {
	for _, i := range VEDQList {
		query := []*dbox.Filter{}
		query = append(query, dbox.Eq("VEId", int(i.Id)))

		CapacityPaymentDocuments := []VEDQCapacityPaymentDocuments{}
		csr, _ := ctx.Find(new(VEDQCapacityPaymentDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&CapacityPaymentDocuments, 0, false)
			i.CapacityPaymentDocuments = CapacityPaymentDocuments
		}
		csr.Close()

		BackupFuelDocuments := []VEDQBackupFuelDocuments{}
		csr, _ = ctx.Find(new(VEDQBackupFuelDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&BackupFuelDocuments, 0, false)
			i.BackupFuelDocuments = BackupFuelDocuments
		}
		csr.Close()

		EnergyPaymentDocuments := []VEDQEnergyPaymentDocuments{}
		csr, _ = ctx.Find(new(VEDQEnergyPaymentDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&EnergyPaymentDocuments, 0, false)
			i.EnergyPaymentDocuments = EnergyPaymentDocuments
		}
		csr.Close()

		MaintenanceCostDocuments := []VEDQMaintenanceCostDocuments{}
		csr, _ = ctx.Find(new(VEDQMaintenanceCostDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&MaintenanceCostDocuments, 0, false)
			i.MaintenanceCostDocuments = MaintenanceCostDocuments
		}
		csr.Close()

		MaintenanceDurationDocuments := []VEDQMaintenanceDurationDocuments{}
		csr, _ = ctx.Find(new(VEDQMaintenanceDurationDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&MaintenanceDurationDocuments, 0, false)
			i.MaintenanceDurationDocuments = MaintenanceDurationDocuments
		}
		csr.Close()

		PenaltyDocuments := []VEDQPenaltyDocuments{}
		csr, _ = ctx.Find(new(VEDQPenaltyDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&PenaltyDocuments, 0, false)
			i.PenaltyDocuments = PenaltyDocuments
		}
		csr.Close()

		IncentiveDocuments := []VEDQIncentiveDocuments{}
		csr, _ = ctx.Find(new(VEDQIncentiveDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&IncentiveDocuments, 0, false)
			i.IncentiveDocuments = IncentiveDocuments
		}
		csr.Close()

		PrimaryFuel1stDocuments := []VEDQPrimaryFuel1stDocuments{}
		csr, _ = ctx.Find(new(VEDQPrimaryFuel1stDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&PrimaryFuel1stDocuments, 0, false)
			i.PrimaryFuel1stDocuments = PrimaryFuel1stDocuments
		}
		csr.Close()

		PrimaryFuel2ndDocuments := []VEDQPrimaryFuel2ndDocuments{}
		csr, _ = ctx.Find(new(VEDQPrimaryFuel2ndDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&PrimaryFuel2ndDocuments, 0, false)
			i.PrimaryFuel2ndDocuments = PrimaryFuel2ndDocuments
		}
		csr.Close()

		StartupPaymentDocuments := []VEDQStartupPaymentDocuments{}
		csr, _ = ctx.Find(new(VEDQStartupPaymentDocuments), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			csr.Fetch(&StartupPaymentDocuments, 0, false)
			i.StartupPaymentDocuments = StartupPaymentDocuments
		}
		csr.Close()
	}
}
Ejemplo n.º 2
0
func (m *HistoricalValueEquation) GetDataQuality(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
	type DataValue struct {
		ID                       string
		Plant                    string  `json:'Plant'`
		Unit                     string  `json:'Unit'`
		Count                    float64 `json:'Count'`
		CapacityPayment_Data     float64 `json:'CapacityPayment_Data'`
		EnergyPayment_Data       float64 `json:'EnergyPayment_Data'`
		StartupPayment_Data      float64 `json:'StartupPayment_Data'`
		Penalty_Data             float64 `json:'Penalty_Data'`
		Incentive_Data           float64 `json:'Incentive_Data'`
		MaintenanceCost_Data     float64 `json:'MaintenanceCost_Data'`
		MaintenanceDuration_Data float64 `json:'MaintenanceDuration_Data'`
		PrimaryFuel1st_Data      float64 `json:'PrimaryFuel1st_Data'`
		PrimaryFuel2nd_Data      float64 `json:'PrimaryFuel2nd_Data'`
		BackupFuel_Data          float64 `json:'BackupFuel_Data'`
		FuelTransport_Data       float64 `json:'FuelTransport_Data'`
	}

	m.SetPayLoad(k)
	var e error = nil
	result := []*DataValue{}
	c := ctx.Connection
	vedq := ValueEquationDataQuality{}
	query := []*dbox.Filter{}
	query = append(query, dbox.Gte("Dates", m.StartPeriod))
	query = append(query, dbox.Lte("Dates", m.EndPeriod))
	groupBy := "Plant"
	switch m.Scope {
	case "Kingdom":
		break
	case "Plant":
		if m.Selected != nil && len(m.Selected) > 0 {
			query = append(query, dbox.In("Plant", m.Selected))
		}
		groupBy = "Unit"
		break
	case "Phase":
		if m.Selected != nil && len(m.Selected) > 0 {
			query = append(query, dbox.In("Phase", m.Selected))
		}
		break
	case "Unit":
		query = append(query, dbox.Eq("Plant", m.SelectedPlant))
		if m.Selected != nil && len(m.Selected) > 0 {
			query = append(query, dbox.In("Unit", m.Selected))
		}
		groupBy = "Unit"
		break
	default:
		break
	}

	if m.Scope == "Unit" || (m.Scope == "Plant" && m.Selected != nil && len(m.Selected) == 1) {
		query := []*dbox.Filter{}
		query = append(query, dbox.Gte("Dates", m.StartPeriod))
		query = append(query, dbox.Lte("Dates", m.EndPeriod))
		if m.Scope == "Unit" {
			query = append(query, dbox.Eq("Plant", m.SelectedPlant))
			if m.Selected != nil && len(m.Selected) > 0 {
				query = append(query, dbox.In("Unit", m.Selected))
			}
		} else {
			query = append(query, dbox.Eq("Plant", m.Selected[0]))
		}
		temp := []*ValueEquationDataQuality{}
		csr, e := ctx.Find(new(ValueEquationDataQuality), tk.M{}.Set("where", dbox.And(query...)))
		if csr != nil {
			e = csr.Fetch(&temp, 0, false)
		}
		csr.Close()
		if e != nil {
			return nil, e
		} else {
			m.GetValueEquationDocument(ctx, temp)
			return temp, e
		}
	} else {
		csr, e := c.NewQuery().
			Where(query...).Select(groupBy).
			Aggr(dbox.AggrSum, "1", "Count").
			Aggr(dbox.AggrSum, "CapacityPayment_Data", "CapacityPayment_Data").
			Aggr(dbox.AggrSum, "EnergyPayment_Data", "EnergyPayment_Data").
			Aggr(dbox.AggrSum, "StartupPayment_Data", "StartupPayment_Data").
			Aggr(dbox.AggrSum, "Penalty_Data", "Penalty_Data").
			Aggr(dbox.AggrSum, "Incentive_Data", "Incentive_Data").
			Aggr(dbox.AggrSum, "MaintenanceCost_Data", "MaintenanceCost_Data").
			Aggr(dbox.AggrSum, "MaintenanceDuration_Data", "MaintenanceDuration_Data").
			Aggr(dbox.AggrSum, "PrimaryFuel1st_Data", "PrimaryFuel1st_Data").
			Aggr(dbox.AggrSum, "PrimaryFuel2nd_Data", "PrimaryFuel2nd_Data").
			Aggr(dbox.AggrSum, "BackupFuel_Data", "BackupFuel_Data").
			Aggr(dbox.AggrSum, "FuelTransport_Data", "FuelTransport_Data").
			From(vedq.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
		if csr != nil {
			e = csr.Fetch(&result, 0, false)
		}
		csr.Close()
		if e != nil {
			return nil, e
		}
		for _, i := range result {
			if i.Unit != "" {
				i.ID = i.Unit
			} else {
				i.ID = i.Plant
			}
		}
	}
	return result, e
}