Example #1
0
func (ec *Controller) Prepare() {
	host := beego.AppConfig.String("db_server")
	username := beego.AppConfig.String("db_username")
	password := beego.AppConfig.String("db_password")
	database := beego.AppConfig.String("db_name")
	dbtype := beego.AppConfig.String("db_type")

	if dbtype != "" {
		db, e := proxy.NewConnection(dbtype, host, username, password, database)
		if e != nil {
			beego.Error(e.Error())
		}
		ec.Db = db
	}

	//fmt.Println("Prepare")
	if ec.Db != nil {
		if e := ec.Db.Connect(); e != nil {
			beego.Error("Unable to connect to database")
		}
		//fmt.Println("Connected")
		ec.Orm = orm.New(ec.Db)
	}
	ec.prepareSession()
}
Example #2
0
func DbCtx() *orm.DataContext {
	conn := DbConn()
	if ctx == nil {
		ctx = orm.New(conn)
	}
	//fmt.Printf("Init ctx. Conn: %v \n", conn)
	return ctx
}
func main() {
	tk.Println("Starting the app..")
	mongo, e := PrepareConnection("mongo")
	if e != nil {
		tk.Println(e)
	}
	ctx = orm.New(mongo)
	GetStructFromCollection("ValueEquation_Dashboard")
	defer ctx.Close()
}
Example #4
0
func TestScan(t *testing.T) {
	var e error

	fmt.Println("Test Scan")
	if econnect := connect(); econnect != nil {
		t.Error("Unable to connect to database")
		return
	}
	defer close()

	ormConn := orm.New(ctx)
	defer ormConn.Close()

	cats := make([]OutageCategory, 0)
	e = ormConn.Find(new(OutageCategory), nil).FetchAll(&cats, true)
	if e != nil {
		t.Error(e.Error())
	}

	os := make([]*Outage, 0)
	e = ormConn.Find(new(Outage), nil).FetchAll(&os, true)
	if e != nil {
		t.Error(e.Error())
	}

	for _, o := range os {
		fmt.Printf("Before: %s \n\n", tk.JsonString(o))
		for k, sum := range o.Summaries {
			for k, i := range sum.Outages {
				i.Valid = false
				i.SuggestedCategoryId = ""
				for _, c := range cats {
					fmt.Printf("Evaluating keyword: %s ...", strings.Join(c.Keywords, ","))
					cok := c.Scan(i.Reason)
					fmt.Printf("%+v \n", cok)
					if cok {
						if i.Valid == false && sum.CategoryId == c.Id {
							fmt.Printf("Tag: %s as valid \n", c.Id)
							i.Valid = true
							i.SuggestedCategoryId = ""
						} else if i.Valid == false {
							fmt.Printf("Suggesting: %s \n", c.Id)
							i.SuggestedCategoryId = c.Id
						}
					}
				}
				sum.Outages[k] = i
			}
			o.Summaries[k] = sum
		}
		o.Sync()
		e = ormConn.Save(o)
		fmt.Printf("After: %s \n\n", tk.JsonString(o))
	}
}
Example #5
0
func SetDb(conn dbox.IConnection, ids ...string) error {
	initDbs()
	CloseDb(ids...)
	dbID := "default"
	if len(ids) > 0 {
		dbID = ids[0]
	}
	var (
		_db *orm.DataContext
		e   bool
	)
	if _db, e = _dbs[dbID]; !e {
		_db = orm.New(conn)
	}
	_dbs[dbID] = _db
	return nil
}
Example #6
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	tk.Println("Starting the app..\n")

	sql, e := PrepareConnection()
	if e != nil {
		tk.Println(e)
	} else {
		base := new(BaseController)
		base.Ctx = orm.New(sql)
		defer base.Ctx.Close()

		/*new(GenSummaryData).Generate(base)
		new(GenMOR).Generate(base)
		new(GenPreventiveCorrectiveSummary).Generate(base)
		new(GenWODurationSummary).Generate(base)
		new(GenWOListSummary).Generate(base)

		new(GenPlantMaster).Generate(base)*/

		// new(GenDataBrowser).Generate(base)
		// new(REFunctionalLocation).Generate(base)
		//new(GenValueEquation).Generate(base)
		//new(GenValueEquation).Generate(base)
		new(GenValueEquationDashboard).Generate(base)
		// new(REFunctionalLocation).Generate(base)
		// new(REWOList).Generate(base)
		// new(RERPPCloseWO).Generate(base)
		// new(REFuelCargo).Generate(base)
		// new(REMaintenanceWO).Generate(base)
		// new(RESyntheticPM).Generate(base, 2014)
		// new(REPerfromanceFactors).Generate(base, "Qurayyah")
		// new(REConsolidated).Generate(base)
		// new(REVBMOperationalData).Generate(base) //Revenue
		// new(REFuelCost).Generate(base)
		// new(REPreventiveMaintenance).Generate(base)
		// new(REPlannedMaintenance).Generate(base)
		// new(REMaintenancePlan).Generate(base)
		// new(RENewObjectType).Generate(base)

	}

	tk.Println("Application Close..")
}
Example #7
0
func init() {
	conn, err := PrepareConnection()
	if err != nil {
		fmt.Println(err)
	}
	ctx := orm.New(conn)

	baseCont := new(BaseController)
	baseCont.Ctx = ctx

	app := knot.NewApp("sec")
	app.ViewsPath = wd + "views/"

	// register controllers
	app.Register(&LoginController{baseCont})
	app.Register(&DashboardController{baseCont})
	app.Register(&DataBrowserController{baseCont})
	app.Register(&ValueEquationController{baseCont})
	app.Register(&ValueEquationComparisonController{baseCont})
	app.Register(&HistoricalValueEquationController{baseCont})
	app.Register(&HypothesisController{baseCont})
	app.Register(&ScenarioSimulation{baseCont})
	app.Register(&UploadDataController{baseCont})
	app.Register(&AccountController{baseCont})
	app.Register(&AdministrationController{baseCont})
	/*app.Register(&InitController{baseCont})
	app.Register(&OrganizationController{baseCont})
	app.Register(&InventoryController{baseCont})
	app.Register(&UomController{baseCont})*/

	app.Static("static", wd+"assets")
	app.Static("files", wd+"files")
	app.LayoutTemplate = "shared/layout.html"
	app.DefaultOutputType = knot.OutputJson
	knot.RegisterApp(app)
}
Example #8
0
func (b *BaseController) SetDb(conn dbox.IConnection) error {
	b.CloseDb()
	b.Ctx = orm.New(conn)
	return nil
}
Example #9
0
func TestModeler(t *testing.T) {
	t.Skip()
	//var e error

	if econnect := connect(); econnect != nil {
		t.Error("Unable to connect to database")
		return
	}
	defer close()

	ormConn := orm.New(ctx)
	defer ormConn.Close()
	ormConn.DeleteMany(new(Outage), nil)

	cats := make([]OutageCategory, 0)
	ormConn.Find(new(OutageCategory), nil).FetchAll(&cats, true)

	findCat := func(id string) *OutageCategory {
		for _, v := range cats {
			if v.Id == id {
				return &v
			}
		}
		return new(OutageCategory).New()
	}

	q := ctx.Query().From("tmpOutages")
	c := q.Cursor(nil)
	defer c.Close()
	var m tk.M
	for b, _ := c.Fetch(&m); b; b, _ = c.Fetch(&m) {
		//if m.Get("Start Date") == "9/30/12" {
		//go func(m tk.M) {
		dt := tk.MakeDate("1/2/06", m.Get("Start Date", "1/1/1980").(string)).UTC()
		tm := tk.MakeDate("15:04� ", m.Get("Start Time", "00:00").(string)).UTC()
		dt = tk.AddTime(dt, tm)
		//fmt.Println(tm)

		dt2 := tk.MakeDate("1/2/06", m.Get("Finish Date", "1/1/1980").(string)).UTC()
		tm2 := tk.MakeDate("15:04� ", m.Get("Finish Time", "00:00").(string)).UTC()
		dt2 = tk.AddTime(dt2, tm2)

		o := new(Outage)
		o.PlantName = m.Get("Plant Name").(string)

		if strings.Contains(o.PlantName, "Ghazlan") {
			o.PlantName = "Ghazlan"
		} else if strings.Contains(o.PlantName, "Rabigh") {
			o.PlantName = "Rabigh"
		}

		o.UnitNo = m.Get("Unit No").(string)
		o.Year = dt.Year()
		o.Month = int(dt.Month())
		o.PrepareId()

		o.Summaries = []OutageSummary{}

		b, e := ormConn.GetById(o, o.Id)
		if b {
			fmt.Printf("Data already exist for %s\n", o.Id)
		} else {
			fmt.Printf("Data is not exist for %s\n", o.Id)
		}

		i := OutageItem{}
		i.CategoryId = m.Get("Outage Type").(string)
		if strings.HasPrefix(i.CategoryId, "FO") {
			i.CategoryId = "FO"
		} else if i.CategoryId == "UC-" {
			i.CategoryId = "UC"
		}
		i.DateFrom = dt
		i.DateTo = dt2
		i.Reason = m.Get("Outage Reason").(string)
		i.Hours = m.GetFloat64("Total")

		cat := findCat(i.CategoryId)
		if cat != nil {
			i.Valid = cat.Scan(i.Reason)
		}
		if i.Valid == false {
			found := false
			for _, cv := range cats {
				found = cv.Scan(i.Reason)
				if found {
					i.SuggestedCategoryId = cv.Id
					break
				}
			}
		}

		o.AddOutage(i, true)

		if e = ormConn.Save(o); e != nil {
			t.Errorf("Unable to save %s => %s", o.Id, e.Error())
		}
		//}(m)
		//}
	}
}
Example #10
0
func SetDb(conn dbox.IConnection) error {
	CloseDb()
	_db = orm.New(conn)
	return nil
}
Example #11
0
func main() {
	tk.Println("Starting the app..")
	mongo, e := PrepareConnection("mongo")
	if e != nil {
		tk.Println(e)
	}

	sql, e := PrepareConnection("mssql")
	if e != nil {
		tk.Println(e)
	}

	base := new(BaseController)
	base.MongoCtx = orm.New(mongo)
	base.SqlCtx = orm.New(sql)

	defer base.MongoCtx.Close()
	defer base.SqlCtx.Close()

	// convert(new(MasterFailureCode), base) //				done
	// convert(new(WOList), base) // 						done
	// convert(new(AnomaliesWOList), base) //				done
	// convert(new(Availability), base) //					done
	// convert(new(Consolidated), base) // 					done
	// convert(new(FuelCost), base) //						done
	// convert(new(FuelTransport), base) // 				done
	// convert(new(FunctionalLocation), base) // 			done
	// convert(new(AnomaliesFunctionalLocation), base) //	done
	// convert(new(GenerationAppendix), base) //			done
	// convert(new(MaintenanceCost), base) //				done
	// convert(new(MaintenanceCostFL), base) //				done
	// convert(new(MaintenanceCostByHour), base) //			done
	// convert(new(MaintenancePlan), base) // 				done
	// convert(new(MaintenanceWorkOrder), base) // 			done
	// convert(new(MappedEquipmentType), base) // 			done
	// convert(new(MasterEquipmentType), base) // 			done
	// convert(new(MasterMROElement), base) // 				done
	// convert(new(MasterOrderType), base) // 				done
	// convert(new(MasterPlant), base) // 					done
	// convert(new(NewEquipmentType), base) // 				done
	// convert(new(NotificationFailure), base) // 			done
	// convert(new(NotificationFailureNoYear), base) // 	done
	// convert(new(OperationalData), base) // 				done
	// convert(new(PerformanceFactors), base) // 			done
	// convert(new(PlannedMaintenance), base) // 			done
	// convert(new(PowerPlantCoordinates), base) // 		done
	// convert(new(PowerPlantInfo),base) // 				done
	// convert(new(PrevMaintenanceValueEquation), base) // 	done
	// convert(new(RPPCloseWO), base) // 					done
	// convert(new(StartupPaymentAndPenalty), base) // 		done
	// convert(new(SyntheticPM), base) // 					done
	// convert(new(UnitCost), base) // 						done
	// convert(new(Vibration), base) // 					done

	// convert(new(MORSummary), base) // 					done
	// convert(new(MORCalculationFlatSummary), base)   // 	done
	// convert(new(PreventiveCorrectiveSummary), base) //	done
	// convert(new(WODurationSummary), base) // 			done
	// convert(new(WOListSummary), base) // 				done

	// convert(new(FailureAfterPreventiveSummary), base)// 	done
	// convert(new(RegenMasterPlant), base) // 				done
	// convert(new(MasterFailureCode), base) // 			done
	// convert(new(MasterUnitNoTurbineParent), base) // 	done
	// convert(new(DataTempMaintenance), base) // 			done

	// convert(new(SummaryData), base) // 					done
	// convert(new(DataBrowser), base) // 					done
	// convert(new(MasterActivityType), base) // 			done
	// convert(new(MasterUnitPlant), base) // 				done

	migrate := new(MigrateData)
	migrate.BaseController = base

	// migrate.GenerateMasterUnit()

	// migrate.DoCostSheet() // 							done
	// migrate.DoGeneralInfo() // 							done
	// migrate.DoPowerPlantOutages()	//					done
	// migrate.DoValueEquationDataQuality()	//				done
	// migrate.DoValueEquationDashboard()
	// migrate.DoGenerateVibration()						done
	// migrate.DoValueEquation() //							done
	// migrate.DoDataBrowser()								done
	// migrate.DoGenerateDataBrowserSelectedFields() //		done
	// migrate.DoGenerateDataBrowserFields() // 			done

	// migrate.DoMasterUnit()
	// migrate.DoGenerateAssetClass()
	// migrate.DoGenerateAssetType()
	// migrate.DoGenerateAssetLevel()
	// migrate.DoGenerateTempMstPlant()
	//migrate.DoGenerateUnitPower()
	// check := DataChecker{base}
	// check.CheckDetailData()
}