go liteIDE
go liteIDE
1 COMM FILE
package pricetable import (
"fmt"
"math"
"os"
"strings"
) //func ContainMap(target string, ranges map[string]string) bool {
// var flag bool = false
// for k, _ := range ranges {
// if k == target {
// flag = true
// }
// }
// return flag
//} func ContainArray(target string, ranges []string) bool {
var flag bool = false
for _, v := range ranges {
if v == target {
flag = true
}
}
return flag
}
func FilterString(feild string) string { if strings.Index(feild, "CONSULT DUNHAM BUSH") != - {
feild = "-88888"
}
if strings.Index(feild, "Contact factory") != - {
feild = "-88888"
}
if strings.Index(feild, "contact DBY") != - {
feild = "-88888"
} if strings.Index(feild, "Consult factory") != - {
feild = "-88888"
}
if strings.Index(feild, "Consult DBM") != - {
feild = "-33333"
}
if strings.ToUpper(feild) == "STD" {
feild = "-66666"
}
if strings.ToUpper(feild) == "N/A" {
feild = "-77777"
} return feild
} func Exist(filename string) bool {
_, err := os.Stat(filename)
return err == nil || os.IsExist(err)
} func CheckfileExistAndDelete(path string, filename string) { if Exist(path + filename) { errs := os.Remove(path + filename)
if errs == nil {
fmt.Println("delete old file :" + path + filename + " success !")
} else {
fmt.Printf("Error: %s\n", errs)
}
} else {
fmt.Println("file:" + path + filename + " not exist,not need to delete !")
}
} func Writertofile(content string, filename string, path string) { fil, err := os.OpenFile(path+filename, os.O_RDWR|os.O_APPEND, )
//fmt.Println(path + filename)
if err != nil {
//fmt.Printf("Error: %s\n", err)
filnew, errnew := os.Create(filename)
if errnew != nil {
fmt.Printf("Error: %s\n", errnew)
filnew.Close()
return
} else {
fmt.Println(path + filename + " Create success !")
fil = filnew
} }
defer fil.Close()
fil.WriteString(content)
} func CheckErr(err error) {
if err != nil {
panic(err)
}
} func MyRound(f float64, n int) float64 {
pow10_n := math.Pow10(n)
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
} //func strings.TrimLeft(" !!! Achtung !!! ", "! ")
func Substr(str string, start, length int) string {
rs := []rune(str)
rl := len(rs)
end := if start < {
start = rl - + start
}
end = start + length if start > end {
start, end = end, start
} if start < {
start =
}
if start > rl {
start = rl
}
if end < {
end =
}
if end > rl {
end = rl
} return string(rs[start:end])
} //func main() {
// writertofile("content string??", "1filenamestring.sql", "/")
//}
2 TABLE
package pricetable type TableStruct struct {
TableName string
TableColums []string
} func GetTablea() *TableStruct {
ts := new(TableStruct)
ts.TableName = "Tablea"
ts.TableColums = []string{"acolumA", "acolumB"}
return ts
} func GetTableb() *TableStruct {
ts := new(TableStruct)
ts.TableName = "Tableb"
ts.TableColums = []string{"bcolumA", "bcolumB"}
return ts
} func GetTable_my_dbair2() *TableStruct {
ts := new(TableStruct)
ts.TableName = "my_dbair2"
ts.TableColums = []string{
"Basic 380-415/3ph/50Hz (AU )",
"Basic 460V/3ph/60Hz (Non-UL) (AR )",
"Drain Pan (Stainless Steel)",
"Discharge Plenum (Upflow only)",
"Steam Generating Humidifier",
"Hot Gas Bypass DX System Only",
"Liquid Line Solenoid Valve -DX Systems Only (50Hz)",
"Liquid Line Solenoid Valve -DX Systems Only (60Hz)",
"Panel Insulation (Insulflex)",
"Panel Insulation (Double Skin)",
"SKD (Complete built up unit, piping joints to be brazed by othe",
"Variable Frequency Drive (VFD) for Evaporator Blower Motor",
"UnderFloor Water Detector (PinHole Probe)",
"Smoke Detector",
"EEV (50Hz/60Hz)",
"BMS",
"Low Ambient Kit to 7°C/45F (at design ambient 95F)",
"Low Ambient Kit to 0°C/32F (at design ambient 95F)",
"Low Ambient Kit to -10°C/14F (at design ambient 95F)",
"Low Ambient Kit to 7°C/45F (at design ambient 105F)",
"Low Ambient Kit to 0°C/32F (at design ambient 105F)",
"Low Ambient Kit to -10°C/14F (at design ambient 105F)",
"Coil Fin - Hydrophilic",
"Coil Fin - Copper",
"Black Color Epoxy Powder Coating (In lieu of Std Beige Color) ",
} return ts
} //====================for ACPSB==================
func Gettable_my_6acpsb_p() *TableStruct {
ts := new(TableStruct)
ts.TableName = "my_6ACPSB_P"
ts.TableColums = []string{
//"unit_name",
//"model",
"basic-R22",
"basic-R407C",
"INS0.5",
"INS1",
"DWAL",
"LAC1",
"SV",
"HGBP",
"HWC",
"DOL1",
"DOL2",
"MII",
"CTLR",
"ADS-C",
"ADS-E",
"HYD-E",
"HYD-C",
"SPG",
"BotR/S",
"LIGHT",
"24VAC",
"SSB",
"FR",
} return ts
}
3 MAIN
package main import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
"pricetable"
"strconv"
"strings"
) const (
FILEPATH = "D:/test/pricetable/"
DB_USER = "ecatalog"
DB_PASSWORD = "Zx27yeA"
DB_NAME = "spec7"
DB_HOST = "spec2.dunham-bush.com"
DB_PORT = ""
) func main02() {
//for acpsb
//callForACPSB() //for accs
//callForACCS() //for wcps
//callForWCPS() //for ACPSE50HZ
//callForACPSE50HZ() // for ACPSE60HZ
//callForACPSE60HZ() // for Acdsr410a
callForAcdsr410a() } //=============================for Acdsr410a=========start==============
func callForAcdsr410a() {
//Start
fmt.Println("# Execute Start !") //get model ts := pricetable.GetTable_my_pmec_acds_r410_prices() //check file make sure file is new
pricetable.CheckfileExistAndDelete(FILEPATH, ts.TableName+".sql") //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() queryAcdsr410a(ts, db) //Print Execute finished info
fmt.Println("# Execute End !")
}
func queryAcdsr410a(ts *pricetable.TableStruct, db *sql.DB) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
qstr := "SELECT \"model_id\",\"" + v + "\" FROM my_" + strings.TrimLeft(tbname, "my_")
fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var Model_id string
var val string err = rows.Scan(&Model_id, &val)
pricetable.CheckErr(err) if val == "N/A" {
continue
} var vv string f, err := strconv.ParseFloat(val, ) if err == nil {
if v == "CE2_21" {
vv = val
} else {
//do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , ) } } else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) var pixstr string = "insert into " + strings.TrimLeft(tbname, "my_") + " (\"pid\", \"model_id\",\"price_option\", \"y2013\") VALUES ("
contents := pixstr + "(select \"max\"(pid) from " + strings.TrimLeft(tbname, "my_") + ")+1" + " ,'" + strings.Trim(Model_id, " ") + "','" + strings.Trim(v, " ") + "','" + vv + "' );\n" // update sql
//var contents string = "update " + strings.TrimLeft(tbname, "my_") + " set y2013='" + vv + "' where \"model_id\"='" + strings.Trim(Model_id, " ") + "' and \"price_option\"='" + strings.Trim(v, " ") + "';\n"
//update pmec_acds_r410_prices set y2013='7501.92' WHERE "model_id" = '1' and "price_option" = 'ST1' //test print to console
fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } //=============================for Acdsr410a=========END============== //=============================for ACPSE60HZ=========start==============
func callForACPSE60HZ() {
//Start
fmt.Println("# Execute Start !") //get model
ts := pricetable.GetTable_my_6acpse_pg_r410a_60hz_cooling()
//ts := pricetable.GetTable_my_6acpse_phpg_r410a_heat_pump() //check file make sure file is new
pricetable.CheckfileExistAndDelete(FILEPATH, ts.TableName+".sql") //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() //460V/3ph/60Hz (non-UL) -AR
//230V/3ph/60Hz (non-UL) -AN
//208V/3ph/60Hz (non-UL) -CD
//380V/3ph/60Hz (non-UL) -CB var voltages = []string{"-AR", "-AN", "-CD", "-CB"} for _, v := range voltages {
queryACPSE60HZ(ts, db, v)
} //Print Execute finished info
fmt.Println("# Execute End !")
}
func queryACPSE60HZ(ts *pricetable.TableStruct, db *sql.DB, voltage string) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
qstr := "SELECT \"model\",\"" + v + "\" FROM my_" + strings.TrimLeft(tbname, "my_")
//fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var Model string
var val string err = rows.Scan(&Model, &val)
pricetable.CheckErr(err) // if option is endwith in range of voltages and is which
flag, suf := voltageSuffix(v)
if flag && suf != voltage {
continue
} var vv string f, err := strconv.ParseFloat(val, ) if err == nil { //do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , )
} else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
var pixstr string = "insert into " + tbname + " (\"pid\", \"model\", \"price_option\", \"y2013\", \"guid\") VALUES (" contents := pixstr + "(select \"max\"(pid) from " + tbname + ")+1" + " ,\"" + strings.Trim(Model, " ") + "\",\"" + strings.Trim(v, " ") + "\",\"" + vv + "\" , (select \"max\"(guid) from " + tbname + ")+1 ;\n" //test print to console
//fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } func voltageSuffix(vv string) (bool, string) { var flag bool = false
var suf string = "" var voltages = []string{"-AR", "-AN", "-CD", "-CB"}
for _, v := range voltages {
if strings.HasSuffix(vv, v) {
flag = true
suf = v
break
}
}
return flag, suf
} //=============================for ACPSE60HZ=========start============== //=============================for ACPSE50HZ=========start==============
func callForACPSE50HZ() {
//Start
fmt.Println("# Execute Start !") //get model ts := pricetable.Gettable_my_acpse_pg_r410a_50hz_cooling()
//ts := pricetable.Gettable_my_acpse_phpg_r410a_50hz_heat_pump() //check file make sure file is new
pricetable.CheckfileExistAndDelete(FILEPATH, ts.TableName+".sql") //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() queryACPSE50HZ(ts, db) //Print Execute finished info
fmt.Println("# Execute End !")
}
func queryACPSE50HZ(ts *pricetable.TableStruct, db *sql.DB) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
qstr := "SELECT \"model\",\"" + v + "\" FROM my_" + strings.TrimLeft(tbname, "my_")
fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var Model string
var val string err = rows.Scan(&Model, &val)
pricetable.CheckErr(err) var vv string f, err := strconv.ParseFloat(val, ) if err == nil { //do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , )
} else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
var pixstr string = "insert into " + tbname + " (\"pid\", \"model\", \"price_option\", \"y2013\", \"guid\") VALUES (" contents := pixstr + "(select \"max\"(pid) from " + tbname + ")+1" + " ,\"" + strings.Trim(Model, " ") + "\",\"" + strings.Trim(v, " ") + "\",\"" + vv + "\" , (select \"max\"(guid) from " + tbname + ")+1 ;\n" //test print to console
//fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } //=============================for ACPSE50HZ=========END============== //=============================for WCPS=========start==============
func callForWCPS() {
//Start
fmt.Println("# Execute Start !") //get model //ts := pricetable.Gettable_my_6wcps_ch()
//ts := pricetable.Gettable_my_6wcpsb()
//ts := pricetable.Gettable_my_wcps_ch()
//ts := pricetable.Gettable_my_wcpsb()
ts := pricetable.Gettable_my_wcpsb_fb() //check file make sure file is new
pricetable.CheckfileExistAndDelete(FILEPATH, ts.TableName+".sql") //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() // divide condition run different times
var refrigerant407 string = "R407C"
var refrigerant22 string = "R22" if isContainsREF(ts, refrigerant407) == true && isContainsREF(ts, refrigerant22) == true {
queryExeWCPS(ts, "R-407C", db)
queryExeWCPS(ts, "R-22", db)
fmt.Println(" has both ")
} else if isContainsREF(ts, refrigerant22) == true {
queryExeWCPS(ts, "R-22", db)
fmt.Println(" has R-22 ")
} else if isContainsREF(ts, refrigerant407) == true {
queryExeWCPS(ts, "R-407C", db)
fmt.Println(" has R-407C ")
} else {
queryExeWCPS(ts, "R-407C", db)
fmt.Println(" has no ")
} //Print Execute finished info
fmt.Println("# Execute End !")
} func queryExeWCPS(ts *pricetable.TableStruct, refrigerant string, db *sql.DB) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
qstr := "SELECT \"unit_name\",\"model\",\"" + v + "\", \"basic-R22\",\"basic-R407C\" FROM my_" + strings.TrimLeft(tbname, "my_")
//fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var UNIT string
var Model string
var val string
var basic_R22 string
var basic_R407C string err = rows.Scan(&UNIT, &Model, &val, &basic_R22, &basic_R407C)
pricetable.CheckErr(err) if (refrigerant == "R-22") && ((basic_R22 == "N/A") || (strings.Index(v, "R407C") != -)) {
continue
} if (refrigerant == "R-407C") && ((basic_R407C == "N/A") || (strings.Index(v, "R22") != -)) {
continue
} var vv string f, err := strconv.ParseFloat(val, ) if err == nil { //do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , )
} else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
var pixstr string = "insert into " + tbname + " (\"pid\", \"unit_name\", \"model\", \"refrigerant\", \"price_option\", \"y2013\", \"guid\") VALUES (" contents := pixstr + "(select \"max\"(pid) from " + tbname + ")+1" + " ,\"" + strings.Trim(UNIT, " ") + "\",\"" + strings.Trim(Model, " ") + "\",\"" + refrigerant + "\",\"" + strings.Trim(v, " ") + "\",\"" + vv + "\" , (select \"max\"(guid) from " + tbname + ")+1 ;\n" //test print to console
//fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } //=============================for WCPS=========start============== //=============================for ACCS=========start==============
func findNotNA(listvalue []string) int { var index int
for k, n := range listvalue {
if n != "N/A" {
index = k
break
}
}
return index
}
func callForACCS() {
//Start
fmt.Println("# ACCS Execute Start !") //get model //ts := pricetable.Gettable_my_dbair2() //ts := pricetable.Gettable_my_6accs_hp_r22() //--
//ts := pricetable.Gettable_my_6accs_hp_r407c()
//ts := pricetable.Gettable_my_6accs_r22()
//ts := pricetable.Gettable_my_6accs_r407c()
//ts := pricetable.Gettable_my_accs_hp_r22() //----
ts := pricetable.Gettable_my_accs_hp_r407c() //----
//ts := pricetable.Gettable_my_accs_r407c()
//ts := pricetable.Gettable_my_accs_r22() //check file make sure file is new
var accsfilepath = "D:/test/pricetable/" pricetable.CheckfileExistAndDelete(accsfilepath, ts.TableName+".sql") //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() // divide condition run different times var refrigerant string
//my_accs_r407c
//my_accs_r22 if strings.Index(ts.TableName, "r22") != - {
refrigerant = "R-22"
fmt.Println(" has R-22 ")
} else if strings.Index(ts.TableName, "r407c") != - {
refrigerant = "R-407C"
fmt.Println(" has R-407C ")
}
queryExeACCS(ts, refrigerant, db) //Print Execute finished info
fmt.Println("# ACCS Execute End !")
} func queryExeACCS(ts *pricetable.TableStruct, refrigerant string, db *sql.DB) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
qstr := "SELECT \"unit_name\",\"model\",\"" + v + "\", \"" + ts.TableColums[] + "\",\"" + ts.TableColums[] + "\",\"" + ts.TableColums[] + "\",\"" + ts.TableColums[] + "\",\"" + ts.TableColums[] + "\" FROM my_" + strings.TrimLeft(tbname, "my_")
//qstr := "SELECT \"" + v + "\", * FROM my_" + strings.TrimLeft(tbname, "my_") //fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var val string
var UNIT string
var Model string var basicA string
var basicB string
var basicC string
var basicD string
var basicE string err = rows.Scan(&UNIT, &Model, &val, &basicA, &basicB, &basicC, &basicD, &basicE)
pricetable.CheckErr(err) var listvalue = []string{
basicA,
basicB,
basicC,
basicD,
basicE} if !strings.HasPrefix(ts.TableColums[findNotNA(listvalue)], strings.Trim(UNIT, " ")) || val == "N/A" {
//fmt.Println(UNIT, Model, listvalue, val, " = ", v, " : ", ts.TableColums[findNotNA(listvalue)])
continue
} //fmt.Println(UNIT, Model, listvalue, val, " = ", v, " : ", ts.TableColums[findNotNA(listvalue)])
var vv string f, err := strconv.ParseFloat(val, ) if err == nil { //do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , )
} else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
var pixstr string = "insert into " + tbname + " (\"pid\", \"unit_name\", \"model\", \"refrigerant\", \"price_option\", \"y2013\", \"guid\") VALUES (" contents := pixstr + "(select \"max\"(pid) from " + tbname + ")+1" + " ,\"" + strings.Trim(UNIT, " ") + "\",\"" + strings.Trim(Model, " ") + "\",\"" + refrigerant + "\",\"" + strings.Trim(v, " ") + "\",\"" + vv + "\" , (select \"max\"(guid) from " + tbname + ")+1 ;\n" //test print to console
//fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } //=============================for ACCS=========end================ //=============================for ACPSB=========start=============
func isContainsREF(ts *pricetable.TableStruct, refrigerant string) bool { var flag bool = false
for _, v := range ts.TableColums {
//fmt.Println(v, refrigerant)
if strings.Index(strings.ToUpper(v), refrigerant) != - {
flag = true
break
}
}
return flag
} func callForACPSB() {
//Start
fmt.Println("# Execute Start !") //get model //ts := pricetable.Gettable_my_dbair2() //ts := pricetable.Gettable_my_6acpsb_p()
//ts := pricetable.Gettable_my_6acpsb_p_hp()
//ts := pricetable.Gettable_my_acpsb_p()
//ts := pricetable.Gettable_my_acpsb_p_hp()
ts := pricetable.Gettable_my_acps_c() //check file make sure file is new
pricetable.CheckfileExistAndDelete(FILEPATH, ts.TableName+".sql") //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() // divide condition run different times
var refrigerant407 string = "R407C"
var refrigerant22 string = "R22" if isContainsREF(ts, refrigerant407) == true && isContainsREF(ts, refrigerant22) == true {
queryExeACPSB(ts, "R-407C", db)
queryExeACPSB(ts, "R-22", db)
fmt.Println(" has both ")
} else if isContainsREF(ts, refrigerant22) == true {
queryExeACPSB(ts, "R-22", db)
fmt.Println(" has R-22 ")
} else if isContainsREF(ts, refrigerant407) == true {
queryExeACPSB(ts, "R-407C", db)
fmt.Println(" has R-407C ")
} else {
queryExeACPSB(ts, "R-407C", db)
fmt.Println(" has no ")
}
// ACCS TYPE NEED MANUAL PROCESS //ACCS 共4回Evaporator Unit Price
//Horizontal type Vertical Type Vertical type Horizontal type
//HEB -D EB -D VEB -D VEB -D-FB //Print Execute finished info
fmt.Println("# Execute End !")
} func queryExeACPSB(ts *pricetable.TableStruct, refrigerant string, db *sql.DB) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
qstr := "SELECT \"unit_name\",\"model\",\"" + v + "\", \"basic-R22\",\"basic-R407C\" FROM my_" + strings.TrimLeft(tbname, "my_")
//fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var UNIT string
var Model string
var val string
var basic_R22 string
var basic_R407C string err = rows.Scan(&UNIT, &Model, &val, &basic_R22, &basic_R407C)
pricetable.CheckErr(err) if (refrigerant == "R-22") && ((basic_R22 == "N/A") || (strings.Index(v, "R407C") != -)) {
continue
} if (refrigerant == "R-407C") && ((basic_R407C == "N/A") || (strings.Index(v, "R22") != -)) {
continue
} var vv string f, err := strconv.ParseFloat(val, ) if err == nil { //do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , )
} else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
var pixstr string = "insert into " + tbname + " (\"pid\", \"unit_name\", \"model\", \"refrigerant\", \"price_option\", \"y2013\", \"guid\") VALUES (" contents := pixstr + "(select \"max\"(pid) from " + tbname + ")+1" + " ,\"" + UNIT + "\",\"" + strings.Trim(Model, " ") + "\",\"" + refrigerant + "\",\"" + v + "\",\"" + vv + "\" , (select \"max\"(guid) from " + tbname + ")+1 ;\n" //test print to console
//fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } //=============================for ACPSB=========end================
单独执行代码 go database executive
package main import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
//"time"
"math"
"os"
"strconv"
) const (
DB_USER = "ecatalog"
DB_PASSWORD = "Zx27yeA"
DB_NAME = "spec7"
DB_HOST = "spec2.dunham-bush.com"
DB_PORT = ""
) //D:\test\postgresql
const path = "D:/test/postgresql/output.txt" var tablecolums []string = []string{
"Basic 380-415/3ph/50Hz (AU )",
"Basic 460V/3ph/60Hz (Non-UL) (AR )",
"Drain Pan (Stainless Steel)",
"Discharge Plenum (Upflow only)",
"Steam Generating Humidifier",
"Hot Gas Bypass DX System Only",
"Liquid Line Solenoid Valve -DX Systems Only (50Hz)",
"Liquid Line Solenoid Valve -DX Systems Only (60Hz)",
"Panel Insulation (Insulflex)",
"Panel Insulation (Double Skin)",
"SKD (Complete built up unit, piping joints to be brazed by othe",
"Variable Frequency Drive (VFD) for Evaporator Blower Motor",
"UnderFloor Water Detector (PinHole Probe)",
"Smoke Detector",
"EEV (50Hz/60Hz)",
"BMS",
"Low Ambient Kit to 7°C/45F (at design ambient 95F)",
"Low Ambient Kit to 0°C/32F (at design ambient 95F)",
"Low Ambient Kit to -10°C/14F (at design ambient 95F)",
"Low Ambient Kit to 7°C/45F (at design ambient 105F)",
"Low Ambient Kit to 0°C/32F (at design ambient 105F)",
"Low Ambient Kit to -10°C/14F (at design ambient 105F)",
"Coil Fin - Hydrophilic",
"Coil Fin - Copper",
"Black Color Epoxy Powder Coating (In lieu of Std Beige Color) ",
} func main() {
queryExe()
}
func queryExe() { dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo)
//expected := `dbname=database host=hostname.remote password=top\ secret port=1234 user=username` checkErr(err)
defer db.Close() fmt.Println("# Querying") fmt.Println(len(tablecolums))
for i, v := range tablecolums {
if false {
fmt.Println(i, v)
} qstr := "SELECT \"UNIT\",\"Model\",\"" + v + "\" FROM my_dbair2"
//fmt.Println(qstr) //rows, err := db.Query("SELECT \"UNIT\",\"Model\" FROM my_dbair2")
rows, err := db.Query(qstr)
checkErr(err) for rows.Next() { var UNIT string
var Model string
var val string
err = rows.Scan(&UNIT, &Model, &val)
checkErr(err) var vv string f, err := strconv.ParseFloat(val, ) if err == nil {
vv = strconv.FormatFloat(myRound(f, ), 'f', , )
//fmt.Println(vv)
} else {
vv = val
//fmt.Println(vv)
}
//fmt.Println(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
//fmt.Printf("%3v | %8v |%8v |\n", UNIT, Model, vv)
var pixstr string = "insert into ppu_air_cooled_50_options_prices (\"pid\", \"unit_name\", \"model\", \"refrigerant\", \"price_option\", \"y2013\", \"guid\") VALUES (" var refrigerant407 string = "R-407C"
//var refrigerant22 string = "R-22"
var refrigerant string refrigerant = refrigerant407 contents := pixstr + "(select \"max\"(pid) from ppu_air_cooled_50_options_prices)+1" + " ,\"" + UNIT + "\",\"" + Model + "\",\"" + refrigerant + "\",\"" + vv + "\" , (select \"max\"(guid) from ppu_air_cooled_50_options_prices)+1 ;\n"
fmt.Println(contents)
writertofile(contents) }
} }
func writertofile(content string) { fil, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND, )
if err != nil {
fmt.Printf("Error: %s\n", err)
return
}
defer fil.Close()
fil.WriteString(content)
}
func checkErr(err error) {
if err != nil {
panic(err)
}
} func myRound(f float64, n int) float64 {
pow10_n := math.Pow10(n)
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
}
go liteIDE的更多相关文章
- 搭建Go开发及调试环境(LiteIDE + GoClipse) -- Windows篇
这里以Windows7 64位为例,如果是32位环境需安装对应版本程序. 一.安装golang1.2.2 1.3及1.3.1编译生成的二进制文件,无法使用LiteIDE23.2携带的gdb7.7进 ...
- golang,liteide设置 windows7(64)
1.安转go的环境,exe安装包 2.下载liteide27.2.1 3.打开liteide开始开发,在里面添加gopath,无法读取windows里面的gopath设置,不知道什么原因,以管理员运行 ...
- go语言编辑器:liteide
LiteIDE is a simple, open source, cross-platform Go IDE. LiteIDE是一款开源.跨平台的轻量级Go语言集成开发环境(IDE). 项目地址:h ...
- golang debug with LiteIDE
golang 的调试比较麻烦,debug stop into 无法跳转到自己写的代码,但是能够跳转到系统提供的代码. 以下是简单的测试代码: package main import ( "f ...
- 【Go语言】LiteIDE使用的个人使用方法
Go语言开发 可以使用的IDE很多 (Goclipse,sublime,notepad++,vim等)目前使用的最顺手的就是LiteIDE了 但是尽管这样,一开始使用LiteIDE也有很多不习惯的地方 ...
- 修改LiteIDE 编辑窗口的主题
用习惯了Visual Studio 再看其他编译器总是有点别扭,当然LiteIDE 也是能够自定义主题的,再次感叹作者的用心. 依次: 查看 -> 选项 -> LiteEditor 在编辑 ...
- 在LiteIDE 中增加build 的参数
问题: go build 时候其实可以带参数的,但是我们直接运行liteIDE 就找不到 特别对于 Walk 这个gui 需要 -ldflags="-H windowsgui" 把 ...
- 搭建Go开发及调试环境(LiteIDE + GoClipse)
搭建Go开发及调试环境(LiteIDE + GoClipse) -- Windows篇 这里以Windows7 64位为例,如果是32位环境需安装对应版本程序. 一.安装golang1.2.2 1.3 ...
- LiteIDE灰调配色方案
说明 本文写于2017-04-03,使用LiteIDE X31(基于Qt 4.8.5),操作系统为Windows. 使用 LiteIDE下载后解压即可使用.配色方案的所有配置文件都位于liteide/ ...
随机推荐
- 【原创】CDM添加新磁盘,然后负载
hdfs快占满了,所以为节点中添加新的磁盘(这块是个教训,以后用新的节点时,磁盘需要一次性插满,省得后续再添加磁盘了) 注意: 添加磁盘时,不仅仅datanode在配置时添加节点,nodemanage ...
- jquery优化02
缓存变量:DOM遍历是昂贵的,所以尽量将会重用的元素缓存. $element = $('#element'); h = $element.height(); //缓存 $element.css('he ...
- Oracle 使用小计(3)
1.出错处理 ORA-00911: invalid character. 这是因为在语句末尾加上了";"的缘故,去掉";"SQL就可以执行了~ (这与SQL ...
- 海贼王之——梦想音乐
相信和很多海粉一样,对伙伴的关照和战斗,是相当地震撼. 好东西时不时地听一下,然后感受那种刷新全身表层细胞,触电...: 音乐链接: http://v.youku.com/v_show/i ...
- ZOJ2539 Energy Minimization(最小割)
题目大概说,给一个n个格子的矩阵,每个格子都有一个数字pi.求这个函数的最小值: 其中xi的取值是0或1,v0.v1已知,j是和i在矩阵中上下左右相邻的位置且j>i. 这个式子有三个加数组成A+ ...
- android 蓝牙设备监听广播
蓝牙权限 <uses-permission android:name="android.permission.BLUETOOTH" /> 1.监听手机本身蓝牙状态的广播 ...
- ural 1289. One Way Ticket
1289. One Way Ticket Time limit: 1.0 secondMemory limit: 64 MB A crowed of volunteers dressed in the ...
- Spark Streaming实时计算框架介绍
随着大数据的发展,人们对大数据的处理要求也越来越高,原有的批处理框架MapReduce适合离线计算,却无法满足实时性要求较高的业务,如实时推荐.用户行为分析等. Spark Streaming是建立在 ...
- 关于adb驱动
Android设备(如手机)连接PC时所需要的驱动程序,一般Android设备连接WinXP是无需安装驱动的. adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb ...
- 使用GCD
使用GCD 什么是 GCD Grand Central Dispatch (GCD) 是 Apple 开发的一个多核编程的解决方法.该方法在 Mac OS X 10.6 雪豹中首次推出,并随后被引入到 ...