本文整理匯總了Golang中github.com/eaciit/dbox.Gte函數的典型用法代碼示例。如果您正苦於以下問題:Golang Gte函數的具體用法?Golang Gte怎麽用?Golang Gte使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Gte函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetData
func (s *ScenarioSimulation) GetData(k *knot.WebContext) interface{} {
k.Config.OutputType = knot.OutputJson
status := ""
msg := ""
res := []*ValueEquation{}
payloads := struct {
StartPeriod string
EndPeriod string
SelectedPlant []string
SelectedUnit []string
SelectedSimulation string
SelectedDescription string
}{}
e := k.GetPayload(&payloads)
if e != nil {
s.WriteLog(e)
}
start, _ := time.Parse(time.RFC3339, payloads.StartPeriod)
end, _ := time.Parse(time.RFC3339, payloads.EndPeriod)
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", start))
query = append(query, dbox.Lte("Dates", end))
if payloads.SelectedPlant != nil && len(payloads.SelectedPlant) > 0 {
query = append(query, dbox.In("Plant", payloads.SelectedPlant))
}
if payloads.SelectedUnit != nil && len(payloads.SelectedUnit) > 0 {
query = append(query, dbox.In("Unit", payloads.SelectedUnit))
}
csr, err := s.DB().Connection.NewQuery().From("ValueEquation").Select("Plant", "AvgNetGeneration", "VOMR", "TotalOutageDuration", "TotalDuration", "OperatingCost", "Revenue", "TotalLabourCost", "TotalMaterialCost", "TotalServicesCost", "TotalFuelCost").Where(query...).Cursor(nil)
if err != nil {
msg = err.Error()
status = "NOK"
} else {
status = "OK"
}
err = csr.Fetch(&res, 0, true)
defer csr.Close()
result := tk.M{}
result.Set("Status", status)
result.Set("Message", msg)
result.Set("Data", res)
return result
}
示例2: filterCondition
func filterCondition(cond toolkit.M) *dbox.Filter {
fb := new(dbox.Filter)
for key, val := range cond {
if key == "$and" || key == "$or" {
afb := []*dbox.Filter{}
for _, sVal := range val.([]interface{}) {
rVal := sVal.(map[string]interface{})
mVal := toolkit.M{}
for rKey, mapVal := range rVal {
mVal.Set(rKey, mapVal)
}
afb = append(afb, filterCondition(mVal))
}
if key == "$and" {
fb = dbox.And(afb...)
} else {
fb = dbox.Or(afb...)
}
} else {
if reflect.ValueOf(val).Kind() == reflect.Map {
mVal := val.(map[string]interface{})
tomVal, _ := toolkit.ToM(mVal)
switch {
case tomVal.Has("$eq"):
fb = dbox.Eq(key, tomVal["$eq"].(string))
case tomVal.Has("$ne"):
fb = dbox.Ne(key, tomVal["$ne"].(string))
case tomVal.Has("$regex"):
fb = dbox.Contains(key, tomVal["$regex"].(string))
case tomVal.Has("$gt"):
fb = dbox.Gt(key, tomVal["$gt"].(string))
case tomVal.Has("$gte"):
fb = dbox.Gte(key, tomVal["$gte"].(string))
case tomVal.Has("$lt"):
fb = dbox.Lt(key, tomVal["$lt"].(string))
case tomVal.Has("$lte"):
fb = dbox.Lte(key, tomVal["$lte"].(string))
}
} else {
fb = dbox.Eq(key, val)
}
}
}
return fb
}
示例3: GetData
func (m *ValueEquationComparison) GetData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
type DataValue struct {
Revenue float64 `json:'Revenue'`
MaintenanceCost float64 `json:'MaintenanceCost'`
OperatingCost float64 `json:'OperatingCost'`
NetGeneration float64 `json:'NetGeneration'`
}
result, Result := tk.M{}, []DataValue{}
c := ctx.Connection
ve := ValueEquation{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
if m.SelectedPlant != nil && len(m.SelectedPlant) > 0 {
query = append(query, dbox.In("Plant", m.SelectedPlant))
}
if m.SelectedUnit != nil && len(m.SelectedUnit) > 0 {
query = append(query, dbox.In("Unit", m.SelectedUnit))
}
if m.SelectedUnitGroup != "ALL" {
query = append(query, dbox.In("UnitGroup", m.SelectedUnitGroup))
}
csr, e := c.NewQuery().
Where(query...).
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
From(ve.TableName()).Cursor(nil)
e = csr.Fetch(&Result, 0, false)
if e != nil {
return nil, e
}
csr.Close()
result.Set("Index", m.Index)
result.Set("DataValue", Result)
return result, nil
}
示例4: TestFind
func TestFind(t *testing.T) {
ms := []toolkit.M{}
for i := 1; i <= 10; i++ {
m := toolkit.M{}
m.Set("_id", i)
m.Set("random", toolkit.RandInt(100))
ms = append(ms, m)
}
toolkit.Printf("Original Value\n%s\n", toolkit.JsonString(ms))
indexes := dbox.Find(ms, []*dbox.Filter{
//dbox.Or(dbox.Lt("random", 20), dbox.And(dbox.Gte("random", 60), dbox.Lte("random", 70)))})
dbox.And(dbox.Gte("random", 30), dbox.Lte("random", 80))})
records := []toolkit.M{}
for _, v := range indexes {
records = append(records, ms[v])
}
for _, r := range records {
toolkit.Printf("Record: %s \n", toolkit.JsonString(r))
}
toolkit.Printf("Find %d records of %d records\n", len(indexes), len(ms))
}
示例5: filterCondition
func filterCondition(cond toolkit.M) *dbox.Filter {
fb := new(dbox.Filter)
for key, val := range cond {
if key == "$and" || key == "$or" {
afb := []*dbox.Filter{}
for _, sVal := range val.([]interface{}) {
rVal := sVal.(map[string]interface{})
mVal := toolkit.M{}
for rKey, mapVal := range rVal {
mVal.Set(rKey, mapVal)
}
afb = append(afb, filterCondition(mVal))
}
if key == "$and" {
fb = dbox.And(afb...)
} else {
fb = dbox.Or(afb...)
}
} else {
if toolkit.TypeName(val) == "map[string]interface {}" {
mVal := val.(map[string]interface{})
tomVal, _ := toolkit.ToM(mVal)
switch {
case tomVal.Has("$eq"):
fb = dbox.Eq(key, tomVal["$eq"])
case tomVal.Has("$ne"):
fb = dbox.Ne(key, tomVal["$ne"])
case tomVal.Has("$regex"):
fb = dbox.Contains(key, toolkit.ToString(tomVal["$regex"]))
case tomVal.Has("$gt"):
fb = dbox.Gt(key, tomVal["$gt"])
case tomVal.Has("$gte"):
fb = dbox.Gte(key, tomVal["$gte"])
case tomVal.Has("$lt"):
fb = dbox.Lt(key, tomVal["$lt"])
case tomVal.Has("$lte"):
fb = dbox.Lte(key, tomVal["$lte"])
case tomVal.Has("$in"):
tval := make([]interface{}, 0, 0)
if toolkit.TypeName(tomVal["$in"]) == "[]interface {}" {
for _, tin := range tomVal["$in"].([]interface{}) {
tval = append(tval, tin)
}
} else {
tval = append(tval, tomVal["$in"])
}
fb = dbox.In(key, tval...)
case tomVal.Has("$nin"):
tval := make([]interface{}, 0, 0)
if toolkit.TypeName(tomVal["$nin"]) == "[]interface {}" {
for _, tin := range tomVal["$nin"].([]interface{}) {
tval = append(tval, tin)
}
} else {
tval = append(tval, tomVal["$nin"])
}
fb = dbox.Nin(key, tval...)
}
} else {
fb = dbox.Eq(key, val)
}
}
}
return fb
}
示例6: GetSummaryData
func (m *HistoricalValueEquation) GetSummaryData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
Revenue float64 `json:'Revenue'`
MaintenanceCost float64 `json:'MaintenanceCost'`
OperatingCost float64 `json:'OperatingCost'`
}
result, DataChart, DataDetail := tk.M{}, []DataValue{}, []*DataValue{}
c := ctx.Connection
ve := new(ValueEquation)
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
csr, e := c.NewQuery().
Where(query...).
Select("Plant").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group("Plant").Order("Plant").Cursor(nil)
if e != nil {
return nil, e
}
if csr != nil {
e = csr.Fetch(&DataChart, 0, false)
}
if e != nil {
return nil, e
}
csr.Close()
result.Set("DataChart", DataChart)
groupBy := "Plant"
if m.Scope == "Plant" {
groupBy = "Unit"
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
}
if m.Scope != "Unit" {
csr, e := c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataDetail, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataDetail {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
}
result.Set("DataDetail", DataDetail)
return result, nil
}
示例7: generateMORFlatCalculationSummary
// generateMORFlatCalculationSummary
func (m *GenMOR) generateMORFlatCalculationSummary() error {
ctx := m.BaseController.Ctx
c := ctx.Connection
var (
query []*dbox.Filter
)
tk.Println("Generating MOR Flat Calculation Summary..")
Years := []int{2013, 2014, 2015}
query = []*dbox.Filter{}
query = append(query, dbox.Gte("TopElement", "Maintenance"))
MORSummaryList := []MORSummary{}
csr, e := c.NewQuery().Select("Element").From(new(MORSummary).TableName()).Where(query...).Group("Element").Cursor(nil)
if e != nil {
return e
}
e = csr.Fetch(&MORSummaryList, 0, false)
if e != nil {
return e
}
csr.Close()
for _, year := range Years {
query = []*dbox.Filter{}
query = append(query, dbox.Gte("Period", time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)))
query = append(query, dbox.Lt("Period", time.Date((year+1), 1, 1, 0, 0, 0, 0, time.UTC)))
MaintenanceCostList := []MaintenanceCost{}
csr, e := c.NewQuery().From(new(MaintenanceCost).TableName()).Where(query...).Cursor(nil)
if e != nil {
return e
}
e = csr.Fetch(&MaintenanceCostList, 0, false)
if e != nil {
return e
}
csr.Close()
Plants := crowd.From(&MaintenanceCostList).Group(func(x interface{}) interface{} {
return x.(MaintenanceCost).Plant
}, nil).Exec().Result.Data().([]crowd.KV)
for _, p := range Plants {
plant := p.Key.(string)
EqType := crowd.From(&MaintenanceCostList).Where(func(x interface{}) interface{} {
return x.(MaintenanceCost).Plant == plant
}).Group(func(x interface{}) interface{} {
return x.(MaintenanceCost).EquipmentType
}, nil).Exec().Result.Data().([]crowd.KV)
for _, eqt := range EqType {
eq := eqt.Key.(string)
ActType := crowd.From(&MaintenanceCostList).Where(func(x interface{}) interface{} {
o := x.(MaintenanceCost)
return o.Plant == plant && o.EquipmentType == eq
}).Group(func(x interface{}) interface{} {
return x.(MaintenanceCost).MaintenanceActivityType
}, nil).Exec().Result.Data().([]crowd.KV)
for _, a := range ActType {
act := a.Key.(string)
OrderType := crowd.From(&MaintenanceCostList).Where(func(x interface{}) interface{} {
o := x.(MaintenanceCost)
return o.Plant == plant && o.EquipmentType == eq && o.MaintenanceActivityType == act
}).Group(func(x interface{}) interface{} {
return x.(MaintenanceCost).OrderType
}, nil).Exec().Result.Data().([]crowd.KV)
for _, o := range OrderType {
order := o.Key.(string)
for _, mor := range MORSummaryList {
d := new(MORCalculationFlatSummary)
d.PeriodYear = year
d.OrderType = order
if len(eq) == 1 {
d.EquipmentType = "Other"
} else {
d.EquipmentType = eq
}
if len(eq) == 1 {
d.EquipmentTypeDescription = "Other"
} else {
EqTypeDesc := crowd.From(&MaintenanceCostList).Where(func(x interface{}) interface{} {
o := x.(MaintenanceCost)
return o.Plant == plant && o.EquipmentType == eq
}).Exec().Result.Data().([]MaintenanceCost)
if len(EqTypeDesc) > 0 {
d.EquipmentTypeDescription = EqTypeDesc[0].EquipmentTypeDesc
}
}
d.ActivityType = act
d.Plant = PlantNormalization(plant)
d.Element = mor.Element
//.........這裏部分代碼省略.........
示例8: filterParse
func (d *DataSourceController) filterParse(where toolkit.M) *dbox.Filter {
field := where.Get("field", "").(string)
value := fmt.Sprintf("%v", where["value"])
if key := where.Get("key", "").(string); key == "Eq" {
valueInt, errv := strconv.Atoi(fmt.Sprintf("%v", where["value"]))
if errv == nil {
return dbox.Eq(field, valueInt)
} else {
return dbox.Eq(field, value)
}
} else if key == "Ne" {
valueInt, errv := strconv.Atoi(fmt.Sprintf("%v", where["value"]))
if errv == nil {
return dbox.Ne(field, valueInt)
} else {
return dbox.Ne(field, value)
}
} else if key == "Lt" {
valueInt, errv := strconv.Atoi(fmt.Sprintf("%v", where["value"]))
if errv == nil {
return dbox.Lt(field, valueInt)
} else {
return dbox.Lt(field, value)
}
} else if key == "Lte" {
valueInt, errv := strconv.Atoi(fmt.Sprintf("%v", where["value"]))
if errv == nil {
return dbox.Lte(field, valueInt)
} else {
return dbox.Lte(field, value)
}
} else if key == "Gt" {
valueInt, errv := strconv.Atoi(fmt.Sprintf("%v", where["value"]))
if errv == nil {
return dbox.Gt(field, valueInt)
} else {
return dbox.Gt(field, value)
}
} else if key == "Gte" {
valueInt, errv := strconv.Atoi(fmt.Sprintf("%v", where["value"]))
if errv == nil {
return dbox.Gte(field, valueInt)
} else {
return dbox.Gte(field, value)
}
} else if key == "In" {
valueArray := []interface{}{}
for _, e := range strings.Split(value, ",") {
valueArray = append(valueArray, strings.Trim(e, ""))
}
return dbox.In(field, valueArray...)
} else if key == "Nin" {
valueArray := []interface{}{}
for _, e := range strings.Split(value, ",") {
valueArray = append(valueArray, strings.Trim(e, ""))
}
return dbox.Nin(field, valueArray...)
} else if key == "Contains" {
return dbox.Contains(field, value)
} else if key == "Or" {
subs := where.Get("value", []interface{}{}).([]interface{})
filtersToMerge := []*dbox.Filter{}
for _, eachSub := range subs {
eachWhere, _ := toolkit.ToM(eachSub)
filtersToMerge = append(filtersToMerge, d.filterParse(eachWhere))
}
return dbox.Or(filtersToMerge...)
} else if key == "And" {
subs := where.Get("value", []interface{}{}).([]interface{})
filtersToMerge := []*dbox.Filter{}
for _, eachSub := range subs {
eachWhere, _ := toolkit.ToM(eachSub)
filtersToMerge = append(filtersToMerge, d.filterParse(eachWhere))
}
return dbox.And(filtersToMerge...)
}
return nil
}
示例9: GetDataQuality
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
}
//.........這裏部分代碼省略.........
示例10: GetRevenueData
func (m *HistoricalValueEquation) GetRevenueData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
CapacityPayment float64 `json:'CapacityPayment'`
EnergyPayment float64 `json:'EnergyPayment'`
StartupPayment float64 `json:'StartupPayment'`
PenaltyAmount float64 `json:'PenaltyAmount'`
Incentive float64 `json:'Incentive'`
Revenue float64 `json:'Revenue'`
}
m.SetPayLoad(k)
result, DataChartRevenue, DataChartRevenueEx := tk.M{}, []*DataValue{}, []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
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
}
csr, e := c.NewQuery().
Where(query...).
Aggr(dbox.AggrSum, "CapacityPayment", "CapacityPayment").
Aggr(dbox.AggrSum, "EnergyPayment", "EnergyPayment").
Aggr(dbox.AggrSum, "StartupPayment", "StartupPayment").
Aggr(dbox.AggrSum, "PenaltyAmount", "PenaltyAmount").
Aggr(dbox.AggrSum, "Incentive", "Incentive").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
From(ve.TableName()).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataChartRevenue, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
csr, e = c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "CapacityPayment", "CapacityPayment").
Aggr(dbox.AggrSum, "EnergyPayment", "EnergyPayment").
Aggr(dbox.AggrSum, "StartupPayment", "StartupPayment").
Aggr(dbox.AggrSum, "PenaltyAmount", "PenaltyAmount").
Aggr(dbox.AggrSum, "Incentive", "Incentive").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataChartRevenueEx, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataChartRevenueEx {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
return result.Set("DataChartRevenue", DataChartRevenue).Set("DataChartRevenueEx", DataChartRevenueEx), e
}
示例11: GetOperatingData
func (m *HistoricalValueEquation) GetOperatingData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
OperatingCost float64 `json:'OperatingCost'`
FuelTransportCost float64 `json:'FuelTransportCost'`
Capacity float64 `json:'Capacity'`
NetGeneration float64 `json:'NetGeneration'`
}
type DataTableType struct {
IsPrimaryFuel bool `json:'IsPrimaryFuel'`
FuelType string `json:'FuelType'`
ConvertedFuelConsumed float64 `json:'ConvertedFuelConsumed'`
FuelCostPerUnit float64 `json:'FuelCostPerUnit'`
FuelCost float64 `json:'FuelCost'`
}
m.SetPayLoad(k)
result, DataChart, DataTable, DataTotal, DataDetail := tk.M{}, []tk.M{}, []*DataTableType{}, []*DataValue{}, []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
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
}
// Getting "DataTable" - skip, need $unwind [ $Fuel ]
tempValueEquation := []ValueEquation{}
csr, e := c.NewQuery().
Where(query...).Select("Id").
From(ve.TableName()).Cursor(nil)
if csr != nil {
e = csr.Fetch(&tempValueEquation, 0, false)
}
csr.Close()
VEId := []interface{}{}
for _, i := range tempValueEquation {
VEId = append(VEId, i.Id)
}
csr, e = c.NewQuery().
Where(query...).
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
Aggr(dbox.AggrSum, "FuelTransportCost", "FuelTransportCost").
From(ve.TableName()).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataTotal, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
if m.Scope != "Unit" {
csr, e = c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "Capacity", "Capacity").
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataDetail, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataDetail {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
//.........這裏部分代碼省略.........
示例12: GetMaintenanceData
func (m *HistoricalValueEquation) GetMaintenanceData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
type DataValue struct {
ID string
DataSource string `json:'DataSource'`
WorkOrderType string `json:'WorkOrderType'`
Plant string `json:'Plant'`
Unit string `json:'Unit'`
LaborCost float64 `json:'LaborCost'`
MaterialCost float64 `json:'MaterialCost'`
ServiceCost float64 `json:'ServiceCost'`
}
result, DataMainEx, DataOrder, DataChart, DataTable, Temp, IDList := tk.M{}, []*DataValue{}, []*DataValue{}, []tk.M{}, []DataValue{}, []tk.M{}, []interface{}{}
c := ctx.Connection
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
}
// Get DataMainEx
csr, e := c.NewQuery().
Where(query...).
Select(groupBy).
Aggr(dbox.AggrSum, "TotalLabourCost", "LaborCost").
Aggr(dbox.AggrSum, "TotalMaterialCost", "MaterialCost").
Aggr(dbox.AggrSum, "TotalServicesCost", "ServiceCost").
From(new(ValueEquation).TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if e != nil {
return nil, e
}
if csr != nil {
e = csr.Fetch(&DataMainEx, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataMainEx {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
csr, e = c.NewQuery().
Where(query...).Select("Id").
From(new(ValueEquation).TableName()).Cursor(nil)
if e != nil {
return nil, e
}
if csr != nil {
e = csr.Fetch(&Temp, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range Temp {
IDList = append(IDList, i.GetInt("id"))
}
query = []*dbox.Filter{}
query = append(query, dbox.In("VEId", IDList...))
// Get DataTable
csr, e = c.NewQuery().
Where(query...).
Select("DataSource", "WorkOrderType").
Aggr(dbox.AggrSum, "LaborCost", "LaborCost").
Aggr(dbox.AggrSum, "MaterialCost", "MaterialCost").
Aggr(dbox.AggrSum, "ServiceCost", "ServiceCost").
From(new(ValueEquationDetails).TableName()).Group("DataSource", "WorkOrderType").
Order("DataSource").
Cursor(nil)
//.........這裏部分代碼省略.........
示例13: generateDurationIntervalSummary
// generateDurationIntervalSummary ...
func (d *GenWOListSummary) generateDurationIntervalSummary() error {
years := [3]int{2013, 2014, 2015}
c := d.Ctx.Connection
csr, e := c.NewQuery().From(new(TempMstPlant).TableName()).Cursor(nil)
if e != nil {
return e
} else {
defer csr.Close()
}
MstPlantData := []tk.M{}
e = csr.Fetch(&MstPlantData, 0, false)
for _, year := range years {
query := []*dbox.Filter{}
yearFirst := strconv.Itoa(year)
yearFirst = yearFirst + "-01-01 00:00:00.000"
yearLast := strconv.Itoa(year + 1)
yearLast = yearLast + "-01-01 00:00:00.000"
query = append(query, dbox.And(dbox.Gte("ActualStart", yearFirst), dbox.Lte("ActualFinish", yearLast)))
csr1, e := c.NewQuery().From(new(WOList).TableName()).Where(query...).Order("ActualStart").Cursor(nil)
if e != nil {
return e
} else {
defer csr1.Close()
}
datas := []tk.M{}
e = csr1.Fetch(&datas, 0, false)
if len(datas) > 0 {
for _, data := range datas {
woles := new(WOListSummary)
woles.PeriodYear = year
woles.OrderType = data.GetString("type")
woles.FunctionalLocation = data.GetString("functionallocation")
query = nil
query = append(query, dbox.Eq("FunctionalLocationCode", data.GetString("functionallocation")))
csr2, e := c.NewQuery().From(new(FunctionalLocation).TableName()).Where(query...).Select("CatProf").Cursor(nil)
if e != nil {
return e
} else {
defer csr2.Close()
}
tempResult := []tk.M{}
e = csr2.Fetch(&tempResult, 0, false)
if len(tempResult) > 0 {
woles.EquipmentType = tempResult[0].GetString("catprof")
}
woles.MainenanceOrderCode = data.GetString("ordercode")
woles.NotificationCode = data.GetString("notificationcode")
query = nil
query = append(query, dbox.Eq("FunctionalLocationCode", data.GetString("plant")))
csr3, e := c.NewQuery().From(new(FunctionalLocation).TableName()).Where(query...).Select("Description").Cursor(nil)
if e != nil {
return e
} else {
defer csr3.Close()
}
tempResult = []tk.M{}
e = csr3.Fetch(&tempResult, 0, false)
if len(tempResult) > 0 {
woles.Plant = tempResult[0].GetString("description")
}
woles.PlanStart, e = time.Parse(time.RFC3339, data["scheduledstart"].(string))
if e != nil {
return e
}
woles.PlanEnd, e = time.Parse(time.RFC3339, data["scheduledfinish"].(string))
if e != nil {
return e
}
subTime := woles.PlanEnd.Sub(woles.PlanStart)
woles.PlanDuration = subTime.Hours()
//.........這裏部分代碼省略.........
示例14: generatePreventiveCorrectiveSummary
// generatePreventiveCorrectiveSummary
func (s *GenPreventiveCorrectiveSummary) generatePreventiveCorrectiveSummary() error {
var e error
ctx := s.BaseController.Ctx
c := ctx.Connection
years := [3]int{2013, 2014, 2015}
sintax := "select Distinct(Element) from MORSummary"
csr, e := c.NewQuery().Command("freequery", tk.M{}.Set("syntax", sintax)).Cursor(nil)
defer csr.Close()
if e != nil {
return e
}
MROElements := []tk.M{}
e = csr.Fetch(&MROElements, 0, false)
csr1, e := c.NewQuery().From(new(MasterEquipmentType).TableName()).Cursor(nil)
defer csr1.Close()
if e != nil {
return e
}
query := []*dbox.Filter{}
for _, year := range years {
yearFirst := strconv.Itoa(year)
yearFirst = yearFirst + "-01-01 00:00:00.000"
yearLast := strconv.Itoa(year + 1)
yearLast = yearLast + "-01-01 00:00:00.000"
query = append(query, dbox.And(dbox.Gte("Period", yearFirst), dbox.Lte("Period", yearLast)))
csr2, e := c.NewQuery().From(new(MaintenanceCost).TableName()).Where(query...).Cursor(nil)
defer csr2.Close()
if e != nil {
return e
}
datas := []tk.M{}
e = csr2.Fetch(&datas, 0, false)
Plants := crowd.From(&datas).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("plant")
}, nil).Exec().Result.Data().([]crowd.KV)
if len(Plants) > 0 {
for _, p := range Plants {
plant := p.Key.(string)
EqType := crowd.From(&datas).Where(func(x interface{}) interface{} {
period := x.(tk.M).GetString("period")
return strings.Contains(period, strconv.Itoa(year)) && x.(tk.M).GetString("plant") == plant
}).Exec().Result.Data().([]tk.M)
if len(EqType) > 0 {
EquipmentTypes := crowd.From(&EqType).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("equipmenttype")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, eq := range EquipmentTypes {
EquipmentType := eq.Key.(string)
ActType := crowd.From(&EqType).Where(func(x interface{}) interface{} {
return x.(tk.M).GetString("equipmenttype") == EquipmentType
}).Exec().Result.Data().([]tk.M)
if len(ActType) > 0 {
MaintActivityTypes := crowd.From(&ActType).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("maintenanceactivitytype")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, act := range MaintActivityTypes {
MaintActivityType := act.Key.(string)
OrderType := crowd.From(&ActType).Where(func(x interface{}) interface{} {
return x.(tk.M).GetString("maintenanceactivitytype") == MaintActivityType
}).Exec().Result.Data().([]tk.M)
if len(OrderType) > 0 {
OrderTypes := crowd.From(&OrderType).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("ordertype")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, order := range OrderTypes {
OrderTypeString := order.Key.(string)
OrderNo := crowd.From(&OrderType).Where(func(x interface{}) interface{} {
return x.(tk.M).GetString("ordertype") == OrderTypeString
}).Exec().Result.Data().([]tk.M)
if len(OrderNo) > 0 {
Equipment := crowd.From(&OrderNo).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("equipment")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, eqNo := range Equipment {
eqNoString := eqNo.Key.(string)
for _, element := range MROElements {
_ = element
//.........這裏部分代碼省略.........
示例15: GetPerformanceData
func (m *HistoricalValueEquation) GetPerformanceData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
NetGeneration float64 `json:'NetGeneration'`
PrctWAF float64 `json:'PrctWAF'`
}
m.SetPayLoad(k)
var e error = nil
result := []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
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
}
csr, e := c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
Aggr(dbox.AggrAvr, "PrctWAF", "PrctWAF").
From(ve.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
}