nmc_typhoon_db_client

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 10 Imported by: ? modules, 0 packages

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

nmc-typhoon-db-client

从 NMC 台风数据库检索台风报文

编译

使用 make 命令编译,生成的 nmc_typhoon_db_client 可执行程序保存在 bin 目录下。

使用

nmc_typhoon_db_client get 命令从数据库中检索台风信息并保存到 CSV 文件中。

下面命令检索 2020 年 10 月 25 日 00 时数据,将结果保存到 test.csv 文件中。

nmc_typhoon_db_client \
    get \
    --config ./config.yaml \
    --start-time 2020102500 \
    --output-file ./test.csv

--config 指定配置文件路径,默认使用当前路径下的 config.yaml 文件。

--start-time 指定起始时次,格式 YYYYMMDDHH

--output-file 设置输出 CSV 文件的路径

更多参数

该命令还支持获取时间段内的数据。

--end-time 指定截止时次,默认为空。如果设置,则返回起报时次在 [start_time, end_time] 之间的数据。

--forecast-hour 指定预报时效,单位小时,默认为 0,也支持设置时效范围,例如 0-120 表示 0 到 120 小时。

下面命令检索 2020 年 10 月 25 日 00 时到 2020 年 10 月 26 日 00 时,预报时效在 0 到 120 小时的数据。

nmc_typhoon_db_client \
    get \
    --config ./config.yaml \
    --start-time 2020102500 \
    --end-time 2020102600 \
    --forecast-hour "0-120" \
    --output-file "./test.csv"

配置文件

配置文件包含数据库访问信息,格式如下:

database:
  host: host ip
  database_name: database name
  table_name: table name

  driver: "mysql+pymysql"

  auth:
    user: user name
    password: password

CSV 文件

nmc_typhoon_db_client get 命令生成的 CSV 文件包含表头。 列标题与数据库字段名称相同,请参看 columns.go 文件中的 QueryColumns 对象。

LICENSE

Copyright © 2020, Perilla Roc at nwpc-oper.

nmc-typhoon-db-client is licensed under MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var QueryColumns = []string{
	"xuhao",
	"tfxh",
	"tfbh",
	"tfbhbabj",
	"engname",
	"chnname",
	"center",
	"bwtype",
	"FCSTType",
	"datetime",
	"handletime",
	"validtime",
	"fcsthour",
	"strength",
	"zone",
	"lon",
	"lat",
	"windclass",
	"windv",
	"gusts",
	"pressure",
	"movedir",
	"movespeed",
	"wind6v1",
	"wind6v2",
	"wind6v3",
	"wind6v4",
	"wind7v1",
	"wind7v2",
	"wind7v3",
	"wind7v4",
	"wind10v1",
	"wind10v2",
	"wind10v3",
	"wind10v4",
	"wind12v1",
	"wind12v2",
	"wind12v3",
	"wind12v4",
	"wind7class",
	"wind10class",
	"wind12class",
	"wind6class",
	"memo"}

Functions

func WriteToCSV

func WriteToCSV(records []Record, filePath string) error

Types

type Config

type Config struct {
	Database DatabaseConfig
}

type DataFloat64

type DataFloat64 struct {
	sql.NullFloat64
}

func (*DataFloat64) MarshalCSV

func (d *DataFloat64) MarshalCSV() ([]byte, error)

type DataInt32

type DataInt32 struct {
	sql.NullInt32
}

func (DataInt32) MarshalCSV

func (d DataInt32) MarshalCSV() ([]byte, error)

type DataString

type DataString struct {
	sql.NullString
}

func (DataString) MarshalCSV

func (d DataString) MarshalCSV() ([]byte, error)

type DatabaseConfig

type DatabaseConfig struct {
	Host         string
	DatabaseName string `yaml:"database_name"`
	TableName    string `yaml:"table_name"`

	Auth struct {
		User     string
		Password string
	}
}

type DateTime

type DateTime struct {
	time.Time
}

func (DateTime) MarshalCSV

func (date DateTime) MarshalCSV() ([]byte, error)

type NullDateTime

type NullDateTime struct {
	mysql.NullTime
}

func (NullDateTime) MarshalCSV

func (d NullDateTime) MarshalCSV() ([]byte, error)

type QueryConditions

type QueryConditions struct {
	StartTime    string
	EndTime      string
	ForecastHour string
}

type Record

type Record struct {
	Xuhao       int          `csv:"xuhao"`
	Tfxh        DataString   `csv:"tfxh"`
	Tfbh        DataString   `csv:"tfbh"`
	Tfbhbabj    DataString   `csv:"tfbhbabj"`
	Engname     DataString   `csv:"engname"`
	Chnname     DataString   `csv:"chnname"`
	Center      string       `csv:"center"`
	Bwtype      DataString   `csv:"bwtype"`
	FcstType    string       `db:"FCSTType" csv:"FCSTType"`
	Datetime    NullDateTime `csv:"datetime"`
	Handletime  NullDateTime `csv:"handletime"`
	Validtime   NullDateTime `csv:"validtime"`
	Fcsthour    int          `csv:"fcsthour"`
	Strength    DataString   `csv:"strength"`
	Zone        DataString   `csv:"zone"`
	Lon         DataFloat64  `csv:"lon"`
	Lat         DataFloat64  `csv:"lat"`
	Windclass   DataInt32    `csv:"windclass"`
	Windv       DataFloat64  `csv:"windv"`
	Gusts       DataFloat64  `csv:"gusts"`
	Pressure    DataInt32    `csv:"pressure"`
	Movedir     DataString   `csv:"movedir"`
	Movespeed   DataFloat64  `csv:"movespeed"`
	Wind6v1     DataFloat64  `csv:"wind6v1"`
	Wind6v2     DataFloat64  `csv:"wind6v2"`
	Wind6v3     DataFloat64  `csv:"wind6v3"`
	Wind6v4     DataFloat64  `csv:"wind6v4"`
	Wind7v1     DataFloat64  `csv:"wind7v1"`
	Wind7v2     DataFloat64  `csv:"wind7v2"`
	Wind7v3     DataFloat64  `csv:"wind7v3"`
	Wind7v4     DataFloat64  `csv:"wind7v4"`
	Wind10v1    DataFloat64  `csv:"wind10v1"`
	Wind10v2    DataFloat64  `csv:"wind10v2"`
	Wind10v3    DataFloat64  `csv:"wind10v3"`
	Wind10v4    DataFloat64  `csv:"wind10v4"`
	Wind12v1    DataFloat64  `csv:"wind12v1"`
	Wind12v2    DataFloat64  `csv:"wind12v2"`
	Wind12v3    DataFloat64  `csv:"wind12v3"`
	Wind12v4    DataFloat64  `csv:"wind12v4"`
	Wind7class  DataInt32    `csv:"wind7class"`
	Wind10class DataInt32    `csv:"wind10class"`
	Wind12class DataInt32    `csv:"wind12class"`
	Wind6class  DataInt32    `csv:"wind6class"`
	Memo        DataString   `csv:"memo"`
}

func GetRecords

func GetRecords(
	conditions QueryConditions,
	config DatabaseConfig,
) ([]Record, error)

Directories

Path Synopsis
cli
cmd

Jump to

Keyboard shortcuts

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