0
0

More than 1 year has passed since last update.

Go: 接種状況ダッシュボードのデータを使ってワクチン接種済者をカウントする

Posted at

こちらで行ったのと同じ計算を Go で行いました。
Python3: 接種状況ダッシュボードのデータを使ってワクチン接種済者をカウントする

count_vaccination.go
// ----------------------------------------------------------------
//
//  count_vaccination.go
//
//                  Jan/26/2022
//
// ----------------------------------------------------------------
package main 

import (
    "fmt"
    "os"
    "log"
    "encoding/csv"
//  "reflect"
    "strconv"
    "time"
) 

// ----------------------------------------------------------------
func get_day_6months_proc () string {
    now := time.Now ()
    fmt.Printf ("%s\n" ,now)
    today := strconv.Itoa (now.Year()) + "-" +
        fmt.Sprintf ("%02d",now.Month()) + "-" +
        strconv.Itoa (now.Day())

    t3 := now.AddDate (0,0,-184)
    day_6months := strconv.Itoa (t3.Year()) + "-" +
        fmt.Sprintf ("%02d",t3.Month()) + "-" +
        strconv.Itoa (t3.Day())

    fmt.Println(today)
    fmt.Println(day_6months)

    return  day_6months
}

// ----------------------------------------------------------------
func count_proc(record [][]string,day_6months string){
    llx := len(record)

    second := 0
    second_6months := 0
    third := 0


    for it := 1; it < llx; it++{
        ss,_ := strconv.Atoi(record[it][2])
        second  += ss
        tt,_ := strconv.Atoi(record[it][3])
        third  += tt
        if (record[it][0] < day_6months){
            second_6months += ss
            }
    }

    fmt.Printf ("second = %d\n",second)
    fmt.Printf ("second_6months = %d\n",second_6months)
    fmt.Printf ("third = %d\n",third)
}


// ----------------------------------------------------------------
func main (){
    fmt.Fprintf (os.Stderr,"*** 開始 ***\n")

    file_csv := os.Args[1]
    fmt.Printf (file_csv + "\n")

    ff, err := os.Open(file_csv)
    if err != nil {
        log.Fatal(err)
    }

    rr := csv.NewReader(ff)

    record, err := rr.ReadAll()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("%#v\n", len(record))
//  fmt.Println(reflect.TypeOf(record))

    day_6months := get_day_6months_proc()

    count_proc(record,day_6months)

    fmt.Fprintf (os.Stderr,"*** 終了 ***\n")
}

// ----------------------------------------------------------------

実行結果

$ go run count_vaccination.go summary_by_date.csv
*** 開始 ***
summary_by_date.csv
290
2022-01-26 19:50:18.261192179 +0900 JST m=+0.000425766
2022-01-26
2021-07-26
second = 93846301
second_6months = 29646353
third = 2892327
*** 終了 ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0