cov19data

package module
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 11 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cov19data -- Importing WHO COVID-2019 Cases Global Data

check vulns lint status GitHub license GitHub release

This package is required Go 1.16 or later.

Migrated repository to github.com/goark/cov19data

Usage

Import This Package
import "github.com/goark/cov19data"
Get COVID-2019 Global Data (raw data) from WHO Web Site
//go:build run
// +build run

package main

import (
    "context"
    "fmt"
    "io"
    "os"

    "github.com/goark/cov19data"
    "github.com/goark/fetch"
)

func main() {
    impt, err := cov19data.NewWeb(context.Background(), fetch.New())
    if err != nil {
        fmt.Fprintf(os.Stderr, "%+v\n", err)
        return
    }
    defer impt.Close()
    if _, err := io.Copy(os.Stdout, impt.RawReader()); err != nil {
        fmt.Println(err)
    }
}
Import COVID-2019 Global Data from WHO Web Site to Structured Dataset.
//go:build run
// +build run

package main

import (
    "bytes"
    "context"
    "fmt"
    "io"
    "os"
    "time"

    "github.com/goark/cov19data"
    "github.com/goark/cov19data/entity"
    "github.com/goark/cov19data/filter"
    "github.com/goark/cov19data/values"
    "github.com/goark/errs"
    "github.com/goark/fetch"
)

func getData() ([]*entity.GlobalData, error) {
    impt, err := cov19data.NewWeb(context.Background(), fetch.New())
    if err != nil {
        return nil, errs.Wrap(err)
    }
    defer impt.Close()
    return impt.Data(
        filter.WithPeriod(
            values.NewPeriod(
                values.NewDate(2020, time.Month(9), 1),
                values.NewDate(2020, time.Month(9), 7),
            ),
        ),
        filter.WithCountryCode(values.CC_JP),
        filter.WithRegionCode(values.WPRO),
    )
}

func main() {
    data, err := getData()
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    b, err := entity.ExportCSV(data)
    if err != nil {
        fmt.Printf("%v\n", err)
        return
    }
    if _, err := io.Copy(os.Stdout, bytes.NewReader(b)); err != nil {
        fmt.Println(err)
    }
    // Output:
    // Date_reported,Country_code,Country,WHO_region,New_cases,Cumulative_cases,New_deaths,Cumulative_deaths
    // 2020-09-01,JP,Japan,WPRO,527,68392,17,1296
    // 2020-09-02,JP,Japan,WPRO,609,69001,11,1307
    // 2020-09-03,JP,Japan,WPRO,598,69599,12,1319
    // 2020-09-04,JP,Japan,WPRO,669,70268,11,1330
    // 2020-09-05,JP,Japan,WPRO,608,70876,19,1349
    // 2020-09-06,JP,Japan,WPRO,543,71419,8,1357
    // 2020-09-07,JP,Japan,WPRO,437,71856,6,1363
}
Make Histogram data by COVID-2019 Global Data from WHO Web Site.
//go:build run
// +build run

package main

import (
    "bytes"
    "context"
    "fmt"
    "io"
    "os"
    "time"

    "github.com/goark/cov19data"
    "github.com/goark/cov19data/filter"
    "github.com/goark/cov19data/histogram"
    "github.com/goark/cov19data/values"
    "github.com/goark/errs"
    "github.com/goark/fetch"
)

func getHist() ([]*histogram.HistData, error) {
    impt, err := cov19data.NewWeb(context.Background(), fetch.New())
    if err != nil {
        return nil, errs.Wrap(err)
    }
    defer impt.Close()
    return impt.Histogram(
        values.NewPeriod(
            values.NewDate(2020, time.Month(9), 1),
            values.NewDate(2020, time.Month(9), 28),
        ),
        7,
        filter.WithCountryCode(values.CC_JP),
        filter.WithRegionCode(values.WPRO),
    )
}

func main() {
    hist, err := getHist()
    if err != nil {
        fmt.Fprintf(os.Stderr, "%+v\n", err)
        return
    }
    b, err := histogram.ExportCSV(hist)
    if err != nil {
        fmt.Fprintf(os.Stderr, "%v\n", err)
        return
    }
    if _, err := io.Copy(os.Stdout, bytes.NewReader(b)); err != nil {
        fmt.Println(err)
    }
    // Output:
    // Date_from,Date_to,Cases,Deaths
    // 2020-09-01,2020-09-07,3991,84
    // 2020-09-08,2020-09-14,3801,79
    // 2020-09-15,2020-09-21,3483,58
    // 2020-09-22,2020-09-28,2991,48
}

Modules Requirement Graph

dependency.png

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Import

type Import struct {
	// contains filtered or unexported fields
}

Import class

func New

func New(r io.Reader) *Import

New returns new Import instance

func NewWeb

func NewWeb(ctx context.Context, cli fetch.Client) (*Import, error)

NewWeb returns new Import instance

func (*Import) Close

func (i *Import) Close()

Close method close reader if it has io.Closer interface.

func (*Import) Data

func (i *Import) Data(opts ...filter.FiltersOptFunc) ([]*entity.GlobalData, error)

Data method returns entity.GlobalData list

func (*Import) Histogram

func (i *Import) Histogram(period values.Period, step int, opts ...filter.FiltersOptFunc) ([]*histogram.HistData, error)

Data method returns entity.GlobalData list

func (*Import) RawReader

func (i *Import) RawReader() io.Reader

RawReader method returns raw data stream

Directories

Path Synopsis
sample
data command
hist command
raw command
tokyodata command
tokyohist command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址