0


人工晶状体在线公式A常数优化

人工晶状体在线公式A常数优化

在这里插入图片描述

1. Preparation

1.1 Driver

  • 对应自己电脑Chrome版本的chromedriver.exe

1.2 Data

Data.xlsx

NameALACDK1K1_angleK2K2_angle△K△K_angleWTWLTIOL_PowerRef_postOPOptimized A_constantSexxx23.412.6442.8844.1221.501

1.3 Download

  • 项目下载链接1
  • 项目下载链接2

2. Barret Universal II

2.1 Optimize.go

package main

import("os""fmt""strconv""time""github.com/360EntSecGroup-Skylar/excelize""github.com/tebeka/selenium""./BU2")const(
    chromeDriverPath ="./chromedriver"
    port             =8080)funcmain(){var n int
    fmt.Println("Please input from where to start,default input is 0:")
    fmt.Scanln(&n)// Start a WebDriver server instance
    opts :=[]selenium.ServiceOption{//selenium.Output(os.Stderr),            // Output debug information to STDERR.}//selenium.SetDebug(true)
    selenium.SetDebug(false)
    service, err := selenium.NewChromeDriverService(chromeDriverPath, port, opts...)if err !=nil{panic(err)// panic is used only as an example and is not otherwise recommended.}defer service.Stop()// Connect to the WebDriver instance running locally.
    caps := selenium.Capabilities{"browserName":"chrome"}
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))if err !=nil{panic(err)}defer wd.Quit()// Navigate to the simple playground interface.// Navigate to the simple playground interface.
    err = wd.Get("https://calc.apacrs.org/barrett_universal2105/")if err !=nil{
      fmt.Println("get page faild", err.Error())//return}

    f, err := excelize.OpenFile("Data.xlsx")if err !=nil{
        fmt.Println(err)return}// Get all the rows in the Sheet1.
    DataMap :=make(map[string]string,0)
    rows, err := f.GetRows("Sheet1")for i, row :=range rows {if i>=n{if i ==0{
                f.SetCellValue("Sheet1","N1","Optimized A_constant")continue}else{

                fmt.Println("Processing patient:")
                fmt.Println(i)
                DataMap=map[string]string{"MainContent_PatientName":row[0],//"MainContent_PatientNo":row[1],"MainContent_Aconstant":"118.80","MainContent_Axlength":row[1],"MainContent_MeasuredK1":row[3],"MainContent_MeasuredK2":row[5],"MainContent_OpticalACD":row[2],"MainContent_Refraction":"0","MainContent_LensThickness":row[10],"MainContent_WTW":row[9],"IOL":row[11],"Ref_PostOP":row[12],}/*
                for k,v := range DataMap{
                    fmt.Println(k,v)
                }
                */
                A_constant := BU2.Get_A_constant(wd, DataMap)
                A_constant_ :=strconv.FormatFloat(A_constant,'f',4,64)
                f.SetCellValue("Sheet1","N"+strconv.Itoa(i+1), A_constant_) 
                fmt.Println("Optimized A_constant :"+ A_constant_)
                time.Sleep(5*time.Second)}
            err = f.Save()if err !=nil{
                fmt.Println(err)
                os.Exit(1)}}}}

2.2 BU2

package BU2

import("fmt""strconv"//"time""math""strings""github.com/tebeka/selenium")funcFind_Send(wd selenium.WebDriver, ID string, key string){
   btn, err := wd.FindElement(selenium.ByID, ID)if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(key)if err !=nil{//panic(err)
      fmt.Println(err)}}funcConvertStrSlice2Map(sl []string)map[string]struct{}{
    set :=make(map[string]struct{},len(sl))for_, v :=range sl {
        set[v]=struct{}{}}return set
}funcInMap(m map[string]struct{}, s string)bool{_, ok := m[s]return ok
}funcFloatRound(f float64, n int)float64{
    format :="%."+ strconv.Itoa(n)+"f"
    res,_:= strconv.ParseFloat(fmt.Sprintf(format, f),64)return res
}funcIterate(wd selenium.WebDriver, A_constant float64,IOL string)(Ref float64){
   Patient_Data, err := wd.FindElement(selenium.ByLinkText,"Patient Data")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Patient_Data.Click(); err !=nil{panic(err)}

   btn, err := wd.FindElement(selenium.ByID,"MainContent_Aconstant")if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(strconv.FormatFloat(A_constant,'f',3,64))if err !=nil{//panic(err)
      fmt.Println(err)}//time.Sleep(3 * time.Second)

   Calc, err := wd.FindElement(selenium.ByID,"MainContent_Button1")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Calc.Click(); err !=nil{panic(err)}

   Formula, err := wd.FindElement(selenium.ByLinkText,"Universal Formula")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Formula.Click(); err !=nil{panic(err)}

   t,err :=wd.FindElement(selenium.ByTagName,"tbody")if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}
   Power_Refs := strings.Split(Results,"\n")for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
             Power_Ref_:=strings.Split(strings.TrimSpace(Power_Ref)," ")
            Power_ := Power_Ref_[0]
            Ref_ := Power_Ref_[2]if Power_ == IOL{
                Ref,_= strconv.ParseFloat(Ref_,64)}}}return Ref
}funcAjust(wd selenium.WebDriver, A_constant float64,IOL string,Ref_Post float64, Ref float64)(float64,float64){
   A_constant =FloatRound(A_constant + Ref_Post - Ref,3)
   Ref =Iterate(wd, A_constant, IOL)return Ref, A_constant
}funcMicro_Ajust(wd selenium.WebDriver, A_constant float64, IOL string, _Ref float64, Ref float64,Step float64)(float64,float64,float64){
   A_constant =FloatRound(A_constant + Step,3)
   Ref =Iterate(wd, A_constant, IOL)//fmt.Println(_Ref,Ref)if _Ref > Ref{
    _Step :=FloatRound(math.Abs(Step)/2,4)
    Step = _Step
    fmt.Println("Upaward!")//fmt.Println(Step)}elseif _Ref < Ref{
    _Step :=FloatRound(math.Abs(Step)/2,4)
    Step =- _Step
    fmt.Println("Downaward!")//fmt.Println(Step)}else{
    fmt.Println("Keep original direction!")//fmt.Println(Step)}
   fmt.Printf("Refraction (SE): %.3f A_constant: %.3f next step: %.3f\n", Ref, A_constant, Step)//time.Sleep(10* time.Second)return Ref, A_constant, Step

}funcMicro_Ajust_UpAndDown(wd selenium.WebDriver, A_constant float64,IOL string, Ref float64)(float64){
    fmt.Println("Micro_Ajust_UpAndDown!")
    A_constant_max,A_constant_min :=A_constant,A_constant
    Ref0 :=Ref
    Step :=0.016for{
        _Ref := Ref
        Ref, A_constant_max, Step =Micro_Ajust(wd, A_constant_max,IOL, _Ref, Ref, Step)if _Ref >Ref &&  math.Abs(Step)<=0.001{
            _Ref := Ref
            var A_constant_max0 float64
            Ref, A_constant_max0, Step =Micro_Ajust(wd, A_constant_max,IOL, _Ref, Ref, Step)if _Ref ==Ref{
                A_constant_max=A_constant_max0
            }break}}
    fmt.Println("A_constant_max:"+strconv.FormatFloat(A_constant_max,'f',3,64))

    Ref = Ref0
    Step =-0.016for{
        _Ref := Ref
        Ref, A_constant_min, Step =Micro_Ajust(wd, A_constant_min,IOL,_Ref, Ref, Step)if _Ref < Ref &&  math.Abs(Step)<=0.001{
            _Ref := Ref
            var A_constant_min0 float64
            Ref, A_constant_min0, Step =Micro_Ajust(wd, A_constant_min,IOL,_Ref, Ref, Step)if _Ref ==Ref{
                A_constant_min=A_constant_min0
            }break}}
    fmt.Println("A_constant_min:"+ strconv.FormatFloat(A_constant_min,'f',3,64))
    A_constant = FloatRound ((A_constant_max+A_constant_min)/2,4)return A_constant
}funcGet_A_constant(wd selenium.WebDriver, DataMap map[string]string)(A_constant float64){
    IOL := DataMap["IOL"]
    Ref_PostOP := DataMap["Ref_PostOP"]
    A_constant,_= strconv.ParseFloat(DataMap["MainContent_Aconstant"],64)for k,v :=range DataMap{switch k {case"IOL","Ref_PostOP":continuedefault:Find_Send(wd,k,v)}}//time.Sleep(15*time.Second)
   Calc, err := wd.FindElement(selenium.ByID,"MainContent_Button1")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Calc.Click(); err !=nil{panic(err)}
   Formula, err := wd.FindElement(selenium.ByLinkText,"Universal Formula")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Formula.Click(); err !=nil{panic(err)}

   t,err :=wd.FindElement(selenium.ByTagName,"tbody")if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}//fmt.Println(Results)
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(Power_Refs)
   Power_Refs_Map :=map[string](string){}
   Powers :=[]string{}for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
            _Power_Ref:=strings.Split(Power_Ref," ")
            Power := _Power_Ref[0]
            Powers =append(Powers,Power)
            Ref:=_Power_Ref[2]
            Power_Refs_Map[Power]= Ref
        }}/*
   for Power,Ref := range Power_Refs_Map{
    fmt.Println(Power,Ref)
   }
   *///fmt.Println(Powers)
   set :=ConvertStrSlice2Map(Powers)if!InMap(set,IOL){
    fmt.Println("IOL not in Powers")
    Patient_Data,_:= wd.FindElement(selenium.ByLinkText,"Patient Data")if err := Patient_Data.Click(); err !=nil{panic(err)}return0}else{
        fmt.Printf("IOL in Powers:%s\n",IOL)
        fmt.Printf("Refraction post operation:%s\n",DataMap["Ref_PostOP"])
        Ref,_:= strconv.ParseFloat(Power_Refs_Map[IOL],64)
        Ref_Post,_:= strconv.ParseFloat(Ref_PostOP,64)//fmt.Println(Ref,Ref_Post)for{
                A_constant_ :=FloatRound(A_constant + Ref_Post - Ref,3)//fmt.Println(A_constant_)if!(A_constant_ >=112&& A_constant_<=125){
                    fmt.Println("A_constant out of boundary!")
                    Patient_Data,_:= wd.FindElement(selenium.ByLinkText,"Patient Data")if err := Patient_Data.Click(); err !=nil{panic(err)}return0break}else{
                    _Ref_D :=FloatRound(Ref_Post - Ref,3)
                    Ref, A_constant =Ajust(wd, A_constant,IOL,Ref_Post, Ref)
                    Ref_D :=FloatRound(Ref_Post - Ref,3)//fmt.Println(_Ref_D,Ref_D)if math.Abs(Ref_D)<=0.020{if Ref_D ==0{
                            A_constant =Micro_Ajust_UpAndDown(wd, A_constant, IOL, Ref)break}elseif _Ref_D*Ref_D<0{if Ref_D >0{
                                fmt.Println("Micro_Ajust_Up")
                                Step :=0.002for{
                                    _Ref := Ref
                                    _A_constant := A_constant
                                    Ref, A_constant, Step =Micro_Ajust(wd, A_constant,IOL, _Ref, Ref, Step)
                                    Ref_D =FloatRound(Ref_Post - Ref,2)if Ref_D ==0{
                                        A_constant =Micro_Ajust_UpAndDown(wd, A_constant, IOL, Ref)break}if _Ref > Ref {
                                        fmt.Println(_A_constant,A_constant)
                                        A_constant = FloatRound ((_A_constant +A_constant)/2,4)break}}break}if Ref_D <0{
                                fmt.Println("Micro_Ajust_Down")
                                Step :=-0.002for{
                                    _Ref := Ref
                                    _A_constant := A_constant
                                    Ref, A_constant, Step =Micro_Ajust(wd, A_constant,IOL, _Ref, Ref, Step)
                                    Ref_D =FloatRound(Ref_Post - Ref,2)if Ref_D ==0{
                                        A_constant =Micro_Ajust_UpAndDown(wd, A_constant, IOL, Ref)break}if _Ref < Ref {
                                        fmt.Println(_A_constant,A_constant)
                                        A_constant = FloatRound ((_A_constant +A_constant)/2,4)break}}break}}}}//time.Sleep(10* time.Second)}}//time.Sleep(15 * time.Second)//wd.Quit()
   Patient_Data,_:= wd.FindElement(selenium.ByLinkText,"Patient Data")if err := Patient_Data.Click(); err !=nil{panic(err)}return A_constant
}

2.3 GetRef.go

package main

import("os""fmt""strconv"//"time""strings""github.com/360EntSecGroup-Skylar/excelize""github.com/tebeka/selenium")const(
    chromeDriverPath ="./chromedriver"
    port             =8080)funcmain(){var n int
    fmt.Println("Please input from where to start,default input is 0:")
    fmt.Scanln(&n)// Start a WebDriver server instance
    opts :=[]selenium.ServiceOption{//selenium.Output(os.Stderr),            // Output debug information to STDERR.}//selenium.SetDebug(true)
    selenium.SetDebug(false)
    service, err := selenium.NewChromeDriverService(chromeDriverPath, port, opts...)if err !=nil{panic(err)// panic is used only as an example and is not otherwise recommended.}defer service.Stop()// Connect to the WebDriver instance running locally.
    caps := selenium.Capabilities{"browserName":"chrome"}
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))if err !=nil{panic(err)}defer wd.Quit()// Navigate to the simple playground interface.// Navigate to the simple playground interface.
    err = wd.Get("https://calc.apacrs.org/barrett_universal2105/")if err !=nil{
      fmt.Println("get page faild", err.Error())//return}

    f, err := excelize.OpenFile("Data.xlsx")if err !=nil{
        fmt.Println(err)return}// Get all the rows in the Sheet1.
    DataMap :=make(map[string]string,0)
    rows, err := f.GetRows("Sheet1")for i, row :=range rows {if i>=n{if i ==0{
                f.SetCellValue("Sheet1","R1","Ref with A_constant Optimized ")continue}else{

                fmt.Println("Processing patient:")
                fmt.Println(i)
                DataMap=map[string]string{"MainContent_PatientName":row[0],//"MainContent_PatientNo":row[1],"MainContent_Aconstant":"118.56","MainContent_Axlength":row[1],"MainContent_MeasuredK1":row[3],"MainContent_MeasuredK2":row[5],"MainContent_OpticalACD":row[2],"MainContent_Refraction":"0","MainContent_LensThickness":row[10],"MainContent_WTW":row[9],"IOL":row[11],"Ref_PostOP":row[12],}/*
                for k,v := range DataMap{
                    fmt.Println(k,v)
                }
                */
                Ref :=Get_Ref(wd, DataMap)
                
                f.SetCellValue("Sheet1","R"+strconv.Itoa(i+1), Ref) 
                fmt.Println("Ref with A_constant Optimized :"+ Ref)//time.Sleep(5*time.Second)}
            err = f.Save()if err !=nil{
                fmt.Println(err)
                os.Exit(1)}}}}funcFind_Send(wd selenium.WebDriver, ID string, key string){
   btn, err := wd.FindElement(selenium.ByID, ID)if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(key)if err !=nil{//panic(err)
      fmt.Println(err)}}funcConvertStrSlice2Map(sl []string)map[string]struct{}{
    set :=make(map[string]struct{},len(sl))for_, v :=range sl {
        set[v]=struct{}{}}return set
}funcInMap(m map[string]struct{}, s string)bool{_, ok := m[s]return ok
}funcGet_Ref(wd selenium.WebDriver, DataMap map[string]string)(Ref string){
    IOL := DataMap["IOL"]for k,v :=range DataMap{switch k {case"IOL","Ref_PostOP":continuedefault:Find_Send(wd,k,v)}}//time.Sleep(15*time.Second)
   Calc, err := wd.FindElement(selenium.ByID,"MainContent_Button1")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Calc.Click(); err !=nil{panic(err)}
   Formula, err := wd.FindElement(selenium.ByLinkText,"Universal Formula")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Formula.Click(); err !=nil{panic(err)}

   t,err :=wd.FindElement(selenium.ByTagName,"tbody")if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}//fmt.Println(Results)
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(Power_Refs)
   Power_Refs_Map :=map[string](string){}
   Powers :=[]string{}for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
            _Power_Ref:=strings.Split(Power_Ref," ")
            Power := _Power_Ref[0]
            Powers =append(Powers,Power)
            Ref:=_Power_Ref[2]
            Power_Refs_Map[Power]= Ref
        }}for Power,Ref :=range Power_Refs_Map{
    fmt.Println(Power,Ref)}//fmt.Println(Powers)
   set :=ConvertStrSlice2Map(Powers)if!InMap(set,IOL){
    fmt.Println("IOL not in Powers")
    Patient_Data,_:= wd.FindElement(selenium.ByLinkText,"Patient Data")if err := Patient_Data.Click(); err !=nil{panic(err)}return"---"}else{
        fmt.Printf("IOL in Powers:%s\n",IOL)
        Ref = Power_Refs_Map[IOL]
        Patient_Data,_:= wd.FindElement(selenium.ByLinkText,"Patient Data")if err := Patient_Data.Click(); err !=nil{panic(err)}return Ref
    }}

3. EVO

3.1 Optimize.go

package main

import("os""fmt""strconv"//"time""github.com/360EntSecGroup-Skylar/excelize""github.com/tebeka/selenium""./EVO")const(
    chromeDriverPath ="./chromedriver"
    port             =8080)funcmain(){var n int
    fmt.Println("Please input from where to start,default input is 0:")
    fmt.Scanln(&n)// Start a WebDriver server instance
    opts :=[]selenium.ServiceOption{//selenium.Output(os.Stderr),            // Output debug information to STDERR.}//selenium.SetDebug(true)
    selenium.SetDebug(false)
    service, err := selenium.NewChromeDriverService(chromeDriverPath, port, opts...)if err !=nil{panic(err)// panic is used only as an example and is not otherwise recommended.}defer service.Stop()// Connect to the WebDriver instance running locally.
    caps := selenium.Capabilities{"browserName":"chrome"}
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))if err !=nil{panic(err)}defer wd.Quit()// Navigate to the simple playground interface.// Navigate to the simple playground interface.
    err = wd.Get("https://www.evoiolcalculator.com/calculator.aspx")if err !=nil{
      fmt.Println("get page faild", err.Error())//return}

    f, err := excelize.OpenFile("Data.xlsx")if err !=nil{
        fmt.Println(err)return}// Get all the rows in the Sheet1.
    DataMap :=make(map[string]string,0)
    rows, err := f.GetRows("Sheet1")for i, row :=range rows {if i>=n{if i ==0{
                f.SetCellValue("Sheet1","N1","Optimized A_constant")continue}else{
                fmt.Println("Processing patient:")
                fmt.Println(i)
                DataMap=map[string]string{"TextBoxName":row[0],//"TextBoxID":row[1],"txtAConstant":"118.80","txtAL":row[1],"txtK1":row[3],"txtK2":row[5],"txtACD":row[2],"txtRefraction":"0","txtLT":row[10],//"MainContent_WTW":row[9],"IOL":row[11],"Ref_PostOP":row[12],}/*
                for k,v := range DataMap{
                    fmt.Println(k,v)
                }
                */
                A_constant := EVO.Get_A_constant(wd, DataMap)
                A_constant_ :=strconv.FormatFloat(A_constant,'f',4,64)
                f.SetCellValue("Sheet1","N"+strconv.Itoa(i+1), A_constant_) 
                fmt.Println("Optimized A_constant :"+ A_constant_)//time.Sleep(15*time.Second)}
            err = f.Save()if err !=nil{
                fmt.Println(err)
                os.Exit(1)}}}}

3.2 EVO

package EVO

import("fmt""strconv"//"time""math""strings""github.com/tebeka/selenium")funcFind_Send(wd selenium.WebDriver, ID string, key string){
   btn, err := wd.FindElement(selenium.ByID, ID)if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(key)if err !=nil{//panic(err)
      fmt.Println(err)}}funcConvertStrSlice2Map(sl []string)map[string]struct{}{
    set :=make(map[string]struct{},len(sl))for_, v :=range sl {
        set[v]=struct{}{}}return set
}funcInMap(m map[string]struct{}, s string)bool{_, ok := m[s]return ok
}funcFloatRound(f float64, n int)float64{
    format :="%."+ strconv.Itoa(n)+"f"
    res,_:= strconv.ParseFloat(fmt.Sprintf(format, f),64)return res
}funcIterate(wd selenium.WebDriver, A_constant float64,IOL string)(Ref float64){
   Back, err := wd.FindElement(selenium.ByID,"btnBack")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Back.Click(); err !=nil{panic(err)}

   btn, err := wd.FindElement(selenium.ByID,"txtAConstant")if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(strconv.FormatFloat(A_constant,'f',3,64))if err !=nil{//panic(err)
      fmt.Println(err)}//time.Sleep(3 * time.Second)

   Calc, err := wd.FindElement(selenium.ByID,"btnCalculate")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Calc.Click(); err !=nil{panic(err)}
   div,err :=wd.FindElement(selenium.ByCSSSelector,"#PnPred")if err !=nil{//panic(err)
      fmt.Println(err)}
   t,err :=div.FindElement(selenium.ByCSSSelector,"tbody")if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}
   Power_Refs := strings.Split(Results,"\n")for i,Power_Ref :=range Power_Refs{if i<=5{continue}elseif i<=10{
            Power_Ref_:=strings.Split(strings.TrimSpace(Power_Ref)," ")
            Power_ := Power_Ref_[0]
            Ref_ := Power_Ref_[1]if Power_ == IOL{
                Ref,_= strconv.ParseFloat(Ref_,64)}}}return Ref 
}funcAjust(wd selenium.WebDriver, A_constant float64,IOL string,Ref_Post float64, Ref float64)(float64,float64){
   A_constant =FloatRound(A_constant + Ref_Post - Ref,3)
   Ref =Iterate(wd, A_constant, IOL)return Ref, A_constant
}funcMicro_Ajust(wd selenium.WebDriver, A_constant float64, IOL string, _Ref float64, Ref float64,Step float64)(float64,float64,float64){
   A_constant =FloatRound(A_constant + Step,3)
   Ref =Iterate(wd, A_constant, IOL)//fmt.Println(_Ref,Ref)if _Ref > Ref{
    _Step :=FloatRound(math.Abs(Step)/2,3)
    Step = _Step
    fmt.Println("Upaward!")//fmt.Println(Step)}elseif _Ref < Ref{
    _Step :=FloatRound(math.Abs(Step)/2,3)
    Step =- _Step
    fmt.Println("Downaward!")//fmt.Println(Step)}else{
    fmt.Println("Keep original direction!")//fmt.Println(Step)}//fmt.Println(Ref, A_constant, Step)
   fmt.Printf("Refraction (SE): %.3f A_constant: %.3f next step: %.3f\n", Ref, A_constant, Step)return Ref, A_constant, Step

}funcMicro_Ajust_UpAndDown(wd selenium.WebDriver, A_constant float64,IOL string, Ref float64)(float64){
    fmt.Println("Micro_Ajust_UpAndDown!")
    A_constant_max,A_constant_min :=A_constant,A_constant
    Ref0 :=Ref
    Step :=0.01for{
        _Ref := Ref
        Ref, A_constant_max, Step =Micro_Ajust(wd, A_constant_max,IOL, _Ref, Ref, Step)if _Ref >Ref {break}}
    fmt.Println("A_constant_max:"+strconv.FormatFloat(A_constant_max,'f',3,64))

    Ref = Ref0
    Step =-0.01for{
        _Ref := Ref
        Ref, A_constant_min, Step =Micro_Ajust(wd, A_constant_min,IOL,_Ref, Ref, Step)if _Ref < Ref {break}}
    fmt.Println("A_constant_min:"+ strconv.FormatFloat(A_constant_min,'f',3,64))
    A_constant = FloatRound ((A_constant_max+A_constant_min)/2,4)return A_constant
}funcGet_A_constant(wd selenium.WebDriver, DataMap map[string]string)(A_constant float64){
   IOL := DataMap["IOL"]
   Ref_PostOP := DataMap["Ref_PostOP"]
   A_constant,_= strconv.ParseFloat(DataMap["txtAConstant"],64)for k,v :=range DataMap{switch k {case"IOL","Ref_PostOP":continuedefault:Find_Send(wd,k,v)}}//time.Sleep(3* time.Second)
   Calc, err := wd.FindElement(selenium.ByID,"btnCalculate")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Calc.Click(); err !=nil{panic(err)}//time.Sleep(3* time.Second)
   div,err :=wd.FindElement(selenium.ByCSSSelector,"#PnPred")if err !=nil{//panic(err)
      fmt.Println(err)}
   t,err :=div.FindElement(selenium.ByCSSSelector,"tbody")if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}//fmt.Println(Results)//time.Sleep(5* time.Second)
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(len(Power_Refs))//fmt.Println(Power_Refs)
   Power_Refs_Map :=map[string](string){}
   Powers :=[]string{}for i,Power_Ref :=range Power_Refs{if i<=5{continue}elseif i<=10{
            _Power_Ref:=strings.Split(strings.TrimSpace(Power_Ref)," ")//fmt.Println(_Power_Ref)
            Power := _Power_Ref[0]//fmt.Println(Power)
            Powers =append(Powers,Power)
            Ref:=_Power_Ref[1]
            Power_Refs_Map[Power]= Ref
            //fmt.Println(Ref)}}/*
   for Power,Ref := range Power_Refs_Map{
    fmt.Println(Power,Ref)
   }
   *///fmt.Println(Powers)
   set :=ConvertStrSlice2Map(Powers)if!InMap(set,IOL){
    fmt.Println("IOL not in Powers")
    Back,_:= wd.FindElement(selenium.ByID,"btnBack")if err := Back.Click(); err !=nil{panic(err)}return0}else{
        fmt.Printf("IOL in Powers:%s\n",IOL)
        fmt.Printf("Refraction post operation:%s\n",DataMap["Ref_PostOP"])
        Ref,_:= strconv.ParseFloat(Power_Refs_Map[IOL],64)
        Ref_Post,_:= strconv.ParseFloat(Ref_PostOP,64)//fmt.Println(Ref,Ref_Post)for{
                A_constant_ :=FloatRound(A_constant + Ref_Post - Ref,3)//fmt.Println(A_constant_)if!(A_constant_ >=110&& A_constant_<=125){
                    fmt.Println("A_constant out of boundary!")
                    Back,_:= wd.FindElement(selenium.ByID,"btnBack")if err := Back.Click(); err !=nil{panic(err)}return0break}else{
                    _Ref_D :=FloatRound(Ref_Post - Ref,3)
                    Ref, A_constant =Ajust(wd, A_constant,IOL,Ref_Post, Ref)
                    Ref_D :=FloatRound(Ref_Post - Ref,3)//fmt.Println(_Ref_D,Ref_D)if math.Abs(Ref_D)<=0.02{if Ref_D ==0{
                            A_constant =Micro_Ajust_UpAndDown(wd, A_constant, IOL, Ref)break}elseif _Ref_D*Ref_D<0{if Ref_D >0{
                                fmt.Println("Micro_Ajust_Up")
                                Step :=0.01for{
                                    _Ref := Ref
                                    _A_constant := A_constant
                                    Ref, A_constant, Step =Micro_Ajust(wd, A_constant,IOL, _Ref, Ref, Step)
                                    Ref_D =FloatRound(Ref_Post - Ref,2)if Ref_D ==0{
                                        A_constant =Micro_Ajust_UpAndDown(wd, A_constant, IOL, Ref)break}if _Ref > Ref {
                                        fmt.Println(_A_constant,A_constant)
                                        A_constant = FloatRound ((_A_constant +A_constant)/2,4)break}}break}if Ref_D <0{
                                fmt.Println("Micro_Ajust_Down")
                                Step :=-0.01for{
                                    _Ref := Ref
                                    _A_constant := A_constant
                                    Ref, A_constant, Step =Micro_Ajust(wd, A_constant,IOL, _Ref, Ref, Step)
                                    Ref_D =FloatRound(Ref_Post - Ref,2)if Ref_D ==0{
                                        A_constant =Micro_Ajust_UpAndDown(wd, A_constant, IOL, Ref)break}if _Ref < Ref {
                                        fmt.Println(_A_constant,A_constant)
                                        A_constant = FloatRound ((_A_constant +A_constant)/2,4)break}}break}}}}//time.Sleep(10* time.Second)}}//time.Sleep(15 * time.Second)//wd.Quit()
   Back,_:= wd.FindElement(selenium.ByID,"btnBack")if err := Back.Click(); err !=nil{panic(err)}return A_constant
}

3.3 GetRef.go

package main

import("os""fmt""strconv"//"time""strings""github.com/360EntSecGroup-Skylar/excelize""github.com/tebeka/selenium")const(
    chromeDriverPath ="./chromedriver"
    port             =8080)funcmain(){var n int
    fmt.Println("Please input from where to start,default input is 0:")
    fmt.Scanln(&n)// Start a WebDriver server instance
    opts :=[]selenium.ServiceOption{//selenium.Output(os.Stderr),            // Output debug information to STDERR.}//selenium.SetDebug(true)
    selenium.SetDebug(false)
    service, err := selenium.NewChromeDriverService(chromeDriverPath, port, opts...)if err !=nil{panic(err)// panic is used only as an example and is not otherwise recommended.}defer service.Stop()// Connect to the WebDriver instance running locally.
    caps := selenium.Capabilities{"browserName":"chrome"}
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))if err !=nil{panic(err)}defer wd.Quit()// Navigate to the simple playground interface.// Navigate to the simple playground interface.
    err = wd.Get("https://www.evoiolcalculator.com/calculator.aspx")if err !=nil{
      fmt.Println("get page faild", err.Error())//return}

    f, err := excelize.OpenFile("Data.xlsx")if err !=nil{
        fmt.Println(err)return}// Get all the rows in the Sheet1.
    DataMap :=make(map[string]string,0)
    rows, err := f.GetRows("Sheet1")for i, row :=range rows {if i>=n{if i ==0{
                f.SetCellValue("Sheet1","R1","Ref with A_constant Optimized ")continue}else{

                fmt.Println("Processing patient:")
                fmt.Println(i)
                DataMap=map[string]string{"TextBoxName":row[0],//"TextBoxID":row[1],"txtAConstant":"118.63","txtAL":row[1],"txtK1":row[3],"txtK2":row[5],"txtACD":row[2],"txtRefraction":"0","txtLT":row[10],//"txtCCT":row[9],"IOL":row[11],"Ref_PostOP":row[12],}/*
                for k,v := range DataMap{
                    fmt.Println(k,v)
                }
                */
                Ref :=Get_Ref(wd, DataMap)
                
                f.SetCellValue("Sheet1","R"+strconv.Itoa(i+1), Ref) 
                fmt.Println("Ref with A_constant Optimized :"+ Ref)//time.Sleep(5*time.Second)}
            err = f.Save()if err !=nil{
                fmt.Println(err)
                os.Exit(1)}}}}funcFind_Send(wd selenium.WebDriver, ID string, key string){
   btn, err := wd.FindElement(selenium.ByID, ID)if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(key)if err !=nil{//panic(err)
      fmt.Println(err)}}funcConvertStrSlice2Map(sl []string)map[string]struct{}{
    set :=make(map[string]struct{},len(sl))for_, v :=range sl {
        set[v]=struct{}{}}return set
}funcInMap(m map[string]struct{}, s string)bool{_, ok := m[s]return ok
}funcGet_Ref(wd selenium.WebDriver, DataMap map[string]string)(Ref string){
    IOL := DataMap["IOL"]for k,v :=range DataMap{switch k {case"IOL","Ref_PostOP":continuedefault:Find_Send(wd,k,v)}}//time.Sleep(15*time.Second)
   Calc, err := wd.FindElement(selenium.ByID,"btnCalculate")if err !=nil{//panic(err)
      fmt.Println(err)}if err := Calc.Click(); err !=nil{panic(err)}//time.Sleep(3* time.Second)
   div,err :=wd.FindElement(selenium.ByCSSSelector,"#PnPred")if err !=nil{//panic(err)
      fmt.Println(err)}
   t,err :=div.FindElement(selenium.ByCSSSelector,"tbody")if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}//fmt.Println(Results)//time.Sleep(5* time.Second)
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(len(Power_Refs))//fmt.Println(Power_Refs)
   Power_Refs_Map :=map[string](string){}
   Powers :=[]string{}for i,Power_Ref :=range Power_Refs{if i<=5{continue}elseif i<=10{
            _Power_Ref:=strings.Split(strings.TrimSpace(Power_Ref)," ")//fmt.Println(_Power_Ref)
            Power := _Power_Ref[0]//fmt.Println(Power)
            Powers =append(Powers,Power)
            Ref:=_Power_Ref[1]
            Power_Refs_Map[Power]= Ref
            //fmt.Println(Ref)}}/*
   for Power,Ref := range Power_Refs_Map{
    fmt.Println(Power,Ref)
   }
   *///fmt.Println(Powers)
   set :=ConvertStrSlice2Map(Powers)if!InMap(set,IOL){
    fmt.Println("IOL not in Powers")
    Back,_:= wd.FindElement(selenium.ByID,"btnBack")if err := Back.Click(); err !=nil{panic(err)}return"---"}else{
        fmt.Printf("IOL in Powers:%s\n",IOL)
        Ref = Power_Refs_Map[IOL]
        Back,_:= wd.FindElement(selenium.ByID,"btnBack")if err := Back.Click(); err !=nil{panic(err)}return Ref
    }}

4. Kane

Kane计算公式的网站反应太慢了,十分耗时!

4.1 Optimize.go

package main

import("os""fmt""time""strconv""github.com/360EntSecGroup-Skylar/excelize""github.com/tebeka/selenium""./Kane")const(
    chromeDriverPath ="./chromedriver"
    port             =8080)funcmain(){
    f, err := excelize.OpenFile("Data.xlsx")if err !=nil{
        fmt.Println(err)return}// Get all the rows in the Sheet1.
    DataMap :=make(map[string]string,0)
    rows, err := f.GetRows("Sheet1")var n int
    fmt.Println("Please input from where to start,default input is 0:")
    fmt.Scanln(&n)// Start a WebDriver server instance
    opts :=[]selenium.ServiceOption{//selenium.Output(os.Stderr),            // Output debug information to STDERR.}//selenium.SetDebug(true)
    selenium.SetDebug(false)
    service, err := selenium.NewChromeDriverService(chromeDriverPath, port, opts...)if err !=nil{panic(err)// panic is used only as an example and is not otherwise recommended.}defer service.Stop()// Connect to the WebDriver instance running locally.
    caps := selenium.Capabilities{"browserName":"chrome"}
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))if err !=nil{panic(err)}defer wd.Quit()// Navigate to the simple playground interface.// Navigate to the simple playground interface.
    err = wd.Get("https://www.iolformula.com/")if err !=nil{
      fmt.Println("get page faild", err.Error())//return}
   Agree, err := wd.FindElement(selenium.ByCSSSelector,`div[class="btn btn-primary btn_agreement"]`)if err !=nil{//panic(err)
      fmt.Println(err)}if err := Agree.Click(); err !=nil{panic(err)}
   time.Sleep(5*time.Second)for i, row :=range rows {if i>=n{if i ==0{
                f.SetCellValue("Sheet1","N1","Optimized A_constant")continue}else{
                fmt.Println("Processing patient:")
                fmt.Println(i)
                DataMap=map[string]string{"Patient":row[0],"Sex":row[14],"A-Constant1":"118.80","al-right":row[1],"k1-right":row[3],"k2-right":row[5],"acd-right":row[2],"right-target":"0","lt-right":row[10],//"cct-right":row[],//"MainContent_WTW":row[9],"IOL":row[11],"Ref_PostOP":row[12],}/*
                for k,v := range DataMap{
                    fmt.Println(k,v)
                }
                */
                A_constant := Kane.Get_A_constant(wd, DataMap)
                A_constant_ :=strconv.FormatFloat(A_constant,'f',4,64)
                f.SetCellValue("Sheet1","N"+strconv.Itoa(i+1), A_constant_) 
                fmt.Println("Optimized A_constant :"+ A_constant_)}
            err = f.Save()if err !=nil{
                fmt.Println(err)
                os.Exit(1)}}}}

4.2 Kane

package Kane

import("fmt""strconv""time""math""strings""github.com/tebeka/selenium")funcFind_Send(wd selenium.WebDriver, ID string, key string){
   btn, err := wd.FindElement(selenium.ByID, ID)if err !=nil{//panic(err)
      fmt.Println(err)}

   err =  btn.SendKeys(key)if err !=nil{//panic(err)
      fmt.Println(err)}}funcConvertStrSlice2Map(sl []string)map[string]struct{}{
    set :=make(map[string]struct{},len(sl))for_, v :=range sl {
        set[v]=struct{}{}}return set
}funcInMap(m map[string]struct{}, s string)bool{_, ok := m[s]return ok
}funcFloatRound(f float64, n int)float64{
    format :="%."+ strconv.Itoa(n)+"f"
    res,_:= strconv.ParseFloat(fmt.Sprintf(format, f),64)return res
}funcAjust(wd selenium.WebDriver, A_constant float64,IOL string,Ref_Post float64, Ref float64)(float64,float64){
   A_constant =FloatRound(A_constant + Ref_Post - Ref,3)
   Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
   Back,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(1)")if err := Back.Click(); err !=nil{panic(err)}
   btn, err := wd.FindElement(selenium.ByID,"A-Constant1")if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(strconv.FormatFloat(A_constant,'f',3,64))if err !=nil{//panic(err)
      fmt.Println(err)}
   time.Sleep(3* time.Second)

   menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="button_submit_block form-group submit row jq_class_1"]`)
   Calc,_:= menu.FindElement(selenium.ByCSSSelector,"div:nth-child(1)")if err := Calc.Click(); err !=nil{panic(err)}
   time.Sleep(5* time.Second)
   t,err :=wd.FindElement(selenium.ByCSSSelector,`div[class="res_nontoric"]`)
   Results,err :=t.Text()if err !=nil{panic(err)}
   Power_Refs := strings.Split(Results,"\n")for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
            Power_Ref_:=strings.Split(strings.TrimSpace(Power_Ref)," ")
            Power_ := Power_Ref_[0]
            Ref_ := Power_Ref_[1]if Power_ == IOL{
                Ref,_= strconv.ParseFloat(Ref_,64)}}}return Ref, A_constant
}funcMicro_Ajust(wd selenium.WebDriver, A_constant float64, IOL string, _Ref float64, Ref float64,Step float64)(float64,float64,float64){
   A_constant =FloatRound(A_constant + Step,3)
   Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
   Back,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(1)")if err := Back.Click(); err !=nil{panic(err)}
   btn, err := wd.FindElement(selenium.ByID,"A-Constant1")if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(strconv.FormatFloat(A_constant,'f',3,64))if err !=nil{//panic(err)
      fmt.Println(err)}
   time.Sleep(3* time.Second)
   menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="button_submit_block form-group submit row jq_class_1"]`)
   Calc,_:= menu.FindElement(selenium.ByCSSSelector,"div:nth-child(1)")if err := Calc.Click(); err !=nil{panic(err)}
   time.Sleep(5* time.Second)
   t,err :=wd.FindElement(selenium.ByCSSSelector,`div[class="res_nontoric"]`)if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(Power_Refs)for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
            Power_Ref_:=strings.Split(strings.TrimSpace(Power_Ref)," ")
            Power_ := Power_Ref_[0]
            Ref_ := Power_Ref_[1]//fmt.Println(Power_, Ref_)if Power_ == IOL{
                Ref,_= strconv.ParseFloat(Ref_,64)}}}//fmt.Println(_Ref,Ref)if _Ref > Ref{
    _Step :=FloatRound(math.Abs(Step)/2,3)
    Step = _Step
    fmt.Println("Upaward!")//fmt.Println(Step)}elseif _Ref < Ref{
    _Step :=FloatRound(math.Abs(Step)/2,3)
    Step =- _Step
    fmt.Println("Downaward!")//fmt.Println(Step)}else{
    fmt.Println("Keep original direction!")//fmt.Println(Step)}//fmt.Println(Ref, A_constant, Step)
   fmt.Printf("Refraction (SE): %.3f A_constant: %.3f next step: %.3f\n", Ref, A_constant, Step)return Ref, A_constant, Step

}funcGet_A_constant(wd selenium.WebDriver, DataMap map[string]string)(A_constant float64){
   IOL := DataMap["IOL"]iflen(IOL)<=2{IOL = IOL +".0"}
   Ref_PostOP := DataMap["Ref_PostOP"]
   A_constant,_= strconv.ParseFloat(DataMap["A-Constant1"],64)for k,v :=range DataMap{switch k {case"Sex","IOL","Ref_PostOP":continuedefault:Find_Send(wd,k,v)}}
   time.Sleep(time.Second)//time.Sleep(3* time.Second)
   Sex,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="btn-group radio-group h-gender"]`)
   male,_:= Sex.FindElement(selenium.ByCSSSelector,"label:nth-child(1)")
   female,_:= Sex.FindElement(selenium.ByCSSSelector,"label:nth-child(2)")if DataMap["Sex"]=="1"{if err := male.Click(); err !=nil{panic(err)}}else{if err := female.Click(); err !=nil{panic(err)}}
   Submit,_:= wd.FindElement(selenium.ByCSSSelector,`div[class ="button_submit_block form-group submit row jq_class_1"]`)
   Calc,_:= Submit.FindElement(selenium.ByCSSSelector,"div:nth-child(1)")if err := Calc.Click(); err !=nil{panic(err)}
   time.Sleep(5*time.Second)
   t,err :=wd.FindElement(selenium.ByCSSSelector,`div[class="res_nontoric"]`)if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}//fmt.Println(Results)//time.Sleep(5* time.Second)
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(len(Power_Refs))//fmt.Println(Power_Refs)
   Power_Refs_Map :=map[string](string){}
   Powers :=[]string{}for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
            _Power_Ref:=strings.Split(strings.TrimSpace(Power_Ref)," ")//fmt.Println(_Power_Ref)
            Power := _Power_Ref[0]//fmt.Println(Power)
            Powers =append(Powers,Power)
            Ref:=_Power_Ref[1]
            Power_Refs_Map[Power]= Ref
            //fmt.Println(Ref)}}/*
   for Power,Ref := range Power_Refs_Map{
    fmt.Println(Power,Ref)
   }
   *///fmt.Println(Powers)
   set :=ConvertStrSlice2Map(Powers)if!InMap(set,IOL){
    fmt.Println("IOL not in Powers")
    Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
    NewPatient,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(3)")if err := NewPatient.Click(); err !=nil{panic(err)}return0}else{
        fmt.Printf("IOL in Powers:%s\n",IOL)
        fmt.Printf("Refraction post operation:%s\n",DataMap["Ref_PostOP"])
        Ref,_:= strconv.ParseFloat(Power_Refs_Map[IOL],64)
        Ref_Post,_:= strconv.ParseFloat(Ref_PostOP,64)//fmt.Println(Ref,Ref_Post)for{
                A_constant_ :=FloatRound(A_constant + Ref_Post - Ref,3)//fmt.Println(A_constant_)if!(A_constant_ >=110&& A_constant_<=125){
                    fmt.Println("A_constant out of boundary!")
                    Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
                    NewPatient,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(3)")if err := NewPatient.Click(); err !=nil{panic(err)}return0break}else{
                    _Ref_D :=FloatRound(Ref_Post - Ref,2)
                    Ref, A_constant =Ajust(wd, A_constant,IOL,Ref_Post, Ref)
                    Ref_D :=FloatRound(Ref_Post - Ref,2)//fmt.Println(_Ref_D,Ref_D)if math.Abs(Ref_D)<=0.02{if Ref_D ==0{
                            fmt.Println("Micro_Ajust_UpAndDown!")
                            A_constant_max,A_constant_min :=A_constant,A_constant
                            Ref0 :=Ref
                            Step :=0.002for{
                                _Ref := Ref
                                Ref, A_constant_max, Step =Micro_Ajust(wd, A_constant_max,IOL, _Ref, Ref, Step)if _Ref >Ref {break}}
                            fmt.Println("A_constant_max:"+strconv.FormatFloat(A_constant_max,'f',3,64))

                            Ref = Ref0
                            Step =-0.002for{
                                _Ref := Ref
                                Ref, A_constant_min, Step =Micro_Ajust(wd, A_constant_min,IOL, _Ref, Ref, Step)if _Ref < Ref {break}}
                            fmt.Println("A_constant_min:"+ strconv.FormatFloat(A_constant_min,'f',3,64))
                            A_constant = FloatRound ((A_constant_max+A_constant_min)/2,4)break}elseif _Ref_D*Ref_D<0{if Ref_D >0{
                                fmt.Println("Micro_Ajust_Up")
                                Step :=0.002for{
                                    _Ref := Ref
                                    _A_constant := A_constant
                                    Ref, A_constant, Step =Micro_Ajust(wd, A_constant,IOL, _Ref, Ref, Step)
                                    Ref_D =FloatRound(Ref_Post - Ref,2)if Ref_D ==0{break}if _Ref > Ref {
                                        fmt.Println(_A_constant,A_constant)
                                        A_constant = FloatRound ((_A_constant +A_constant)/2,4)break}}break}if Ref_D <0{
                                fmt.Println("Micro_Ajust_Down")
                                Step :=-0.002for{
                                    _Ref := Ref
                                    _A_constant := A_constant
                                    Ref, A_constant, Step =Micro_Ajust(wd, A_constant,IOL, _Ref, Ref, Step)
                                    Ref_D =FloatRound(Ref_Post - Ref,2)if Ref_D ==0{break}if _Ref < Ref {
                                        fmt.Println(_A_constant,A_constant)
                                        A_constant = FloatRound ((_A_constant +A_constant)/2,4)break}}break}}}}//time.Sleep(10* time.Second)}}//time.Sleep(15 * time.Second)//wd.Quit()
   Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
   NewPatient,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(3)")if err := NewPatient.Click(); err !=nil{panic(err)}//time.Sleep(5*time.Second)return A_constant
}

4.3 GetRef.go

package main

import("os""fmt""strconv""time""strings""github.com/360EntSecGroup-Skylar/excelize""github.com/tebeka/selenium")const(
    chromeDriverPath ="./chromedriver"
    port             =8080)funcmain(){var n int
    fmt.Println("Please input from where to start,default input is 0:")
    fmt.Scanln(&n)// Start a WebDriver server instance
    opts :=[]selenium.ServiceOption{//selenium.Output(os.Stderr),            // Output debug information to STDERR.}//selenium.SetDebug(true)
    selenium.SetDebug(false)
    service, err := selenium.NewChromeDriverService(chromeDriverPath, port, opts...)if err !=nil{panic(err)// panic is used only as an example and is not otherwise recommended.}defer service.Stop()// Connect to the WebDriver instance running locally.
    caps := selenium.Capabilities{"browserName":"chrome"}
    wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))if err !=nil{panic(err)}defer wd.Quit()// Navigate to the simple playground interface.// Navigate to the simple playground interface.
    err = wd.Get("https://www.iolformula.com/")if err !=nil{
      fmt.Println("get page faild", err.Error())//return}
   Agree, err := wd.FindElement(selenium.ByCSSSelector,`div[class="btn btn-primary btn_agreement"]`)if err !=nil{//panic(err)
      fmt.Println(err)}if err := Agree.Click(); err !=nil{panic(err)}
   time.Sleep(5*time.Second)

    f, err := excelize.OpenFile("Data.xlsx")if err !=nil{
        fmt.Println(err)return}// Get all the rows in the Sheet1.
    DataMap :=make(map[string]string,0)
    rows, err := f.GetRows("Sheet1")for i, row :=range rows {if i>=n{if i ==0{
                f.SetCellValue("Sheet1","R1","Ref with A_constant Optimized ")continue}else{

                fmt.Println("Processing patient:")
                fmt.Println(i)
                DataMap=map[string]string{"Patient":row[0],"Sex":row[14],"A-Constant1":"118.80","al-right":row[1],"k1-right":row[3],"k2-right":row[5],"acd-right":row[2],"right-target":"0","lt-right":row[10],//"cct-right":row[],"IOL":row[11],"Ref_PostOP":row[12],}/*
                for k,v := range DataMap{
                    fmt.Println(k,v)
                }
                */
                Ref :=Get_Ref(wd, DataMap)
                
                f.SetCellValue("Sheet1","R"+strconv.Itoa(i+1), Ref) 
                fmt.Println("Ref with A_constant Optimized :"+ Ref)//time.Sleep(5*time.Second)}
            err = f.Save()if err !=nil{
                fmt.Println(err)
                os.Exit(1)}}}}funcFind_Send(wd selenium.WebDriver, ID string, key string){
   btn, err := wd.FindElement(selenium.ByID, ID)if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.Clear()if err !=nil{//panic(err)
      fmt.Println(err)}
   err =  btn.SendKeys(key)if err !=nil{//panic(err)
      fmt.Println(err)}}funcConvertStrSlice2Map(sl []string)map[string]struct{}{
    set :=make(map[string]struct{},len(sl))for_, v :=range sl {
        set[v]=struct{}{}}return set
}funcInMap(m map[string]struct{}, s string)bool{_, ok := m[s]return ok
}funcGet_Ref(wd selenium.WebDriver, DataMap map[string]string)(Ref string){
   IOL := DataMap["IOL"]iflen(IOL)<=2{IOL = IOL +".0"}//fmt.Println(IOL)for k,v :=range DataMap{switch k {case"Sex","IOL","Ref_PostOP":continuedefault:Find_Send(wd,k,v)}}
   time.Sleep(time.Second)//time.Sleep(3* time.Second)
   Sex,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="btn-group radio-group h-gender"]`)
   male,_:= Sex.FindElement(selenium.ByCSSSelector,"label:nth-child(1)")
   female,_:= Sex.FindElement(selenium.ByCSSSelector,"label:nth-child(2)")if DataMap["Sex"]=="1"{if err := male.Click(); err !=nil{panic(err)}}else{if err := female.Click(); err !=nil{panic(err)}}
   Submit,_:= wd.FindElement(selenium.ByCSSSelector,`div[class ="button_submit_block form-group submit row jq_class_1"]`)
   Calc,_:= Submit.FindElement(selenium.ByCSSSelector,"div:nth-child(1)")if err := Calc.Click(); err !=nil{panic(err)}
   time.Sleep(5*time.Second)
   t,err :=wd.FindElement(selenium.ByCSSSelector,`div[class="res_nontoric"]`)if err !=nil{//panic(err)
      fmt.Println(err)}
   Results,err :=t.Text()if err !=nil{panic(err)}//fmt.Println(Results)//time.Sleep(5* time.Second)
   Power_Refs := strings.Split(Results,"\n")//fmt.Println(len(Power_Refs))//fmt.Println(Power_Refs)
   Power_Refs_Map :=map[string](string){}
   Powers :=[]string{}for i,Power_Ref :=range Power_Refs{if i==0{continue}else{
            _Power_Ref:=strings.Split(strings.TrimSpace(Power_Ref)," ")//fmt.Println(_Power_Ref)
            Power := _Power_Ref[0]//fmt.Println(Power)
            Powers =append(Powers,Power)
            Ref:=_Power_Ref[1]
            Power_Refs_Map[Power]= Ref
            //fmt.Println(Ref)}}/*
   for Power,Ref := range Power_Refs_Map{
    fmt.Println(Power,Ref)
   }
   *///fmt.Println(Powers)
   set :=ConvertStrSlice2Map(Powers)if!InMap(set,IOL){
    fmt.Println("IOL not in Powers")
    Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
    NewPatient,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(3)")if err := NewPatient.Click(); err !=nil{panic(err)}return"---"}else{
        fmt.Printf("IOL in Powers:%s\n",IOL)
        Ref = Power_Refs_Map[IOL]
        Menu,_:= wd.FindElement(selenium.ByCSSSelector,`div[class="form-group submit row"]`)
        NewPatient,_:= Menu.FindElement(selenium.ByCSSSelector,"div:nth-child(3)")if err := NewPatient.Click(); err !=nil{panic(err)}return Ref
    }}

标签: golang selenium

本文转载自: https://blog.csdn.net/weixin_45744832/article/details/124621580
版权归原作者 丘比特爱睡觉 所有, 如有侵权,请联系我们删除。

“人工晶状体在线公式A常数优化”的评论:

还没有评论