dean

package module
v0.0.0-...-0254149 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 3 Imported by: 0

README

Dean

一个数据处理、数据清洗的任务流框架

安装
go get github.com/zituocn/dean
使用demo
package main

import (
	"fmt"
	"github.com/zituocn/dean"
)

func main() {

	// 原始数据
	ds := loadData()

	//创建作业
	job := dean.NewJob(ds)

	//添加任务实现
	job.AddTask(new(SomeTask)).
		AddTask(new(OtherTask))

	// 执行作业
	job.Do()

	// 返回最终数据
	result := job.GetData()

	for _, item := range result {
		fmt.Println(item)
	}
}

/*
task 1
*/

type SomeTask struct {
	ds dean.DataSet
}

func (m *SomeTask) LoadData(ds dean.DataSet) {
	fmt.Println("load data")
	m.ds = ds
}

func (m *SomeTask) Process() error {
	fmt.Println("Process")
	m.ds[0]["name"] = "四川大学"
	return nil
}

func (m *SomeTask) Result() dean.DataSet {
	fmt.Println("result")
	return m.ds
}

/*
task 2
*/

type OtherTask struct {
	ds dean.DataSet
}

func (m *OtherTask) LoadData(ds dean.DataSet) {
	fmt.Println("other load data")
	m.ds = ds
}

func (m *OtherTask) Process() error {
	fmt.Println("other Process")
	m.ds[5]["major_name"] = "计算机科学与技术(工科实验班)"
	return nil
}

func (m *OtherTask) Result() dean.DataSet {
	fmt.Println("other result")
	return m.ds
}

func loadData() (ds dean.DataSet) {
	for i := 0; i < 100; i++ {
		dataLine := dean.DataLine{
			"name":          "清华大学",
			"prov_id":       "51",
			"major_name":    "工业设计",
			"number":        "43",
			"min_score":     "664",
			"min_score_def": "166",
			"avg_score":     "665",
			"max_score":     "669",
		}
		ds = append(ds, dataLine)
	}

	return ds
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStructName

func GetStructName(i interface{}) string

func Str2Int

func Str2Int(s string) int

func Str2Int64

func Str2Int64(s string) int64

Str2Int64 string to int64

func ToFloat32

func ToFloat32(v interface{}) float32

ToFloat32 interface to float32

default -1

func ToFloat64

func ToFloat64(v interface{}) float64

ToFloat64 interface to float64

default -1

func ToInt

func ToInt(v interface{}) int

ToInt interface to int

default -1

func ToInt64

func ToInt64(v interface{}) int64

ToInt64 interface to int64

default -1

func ToString

func ToString(v interface{}) string

Types

type DataLine

type DataLine map[string]interface{}

DataLine 一行的数据

type DataMap

type DataMap map[string]DataSet

type DataSet

type DataSet []DataLine

DataSet 一个二维表

type ITask

type ITask interface {

	// LoadData 载入数据
	LoadData(dm DataMap)

	// Process 处理数据
	Process() error

	// Result 返回结果数据
	Result() DataMap
}

ITask 数据处理接口定义

type Job

type Job struct {

	// Tasks 多个等待处理的任务
	Tasks []ITask
	// contains filtered or unexported fields
}

Job 作业

func NewJob

func NewJob(dm DataMap) *Job

NewJob 返回Job实例

载入初始数据
须将待处理的数据,转换成DataSet

func (*Job) AddTask

func (j *Job) AddTask(task ITask) *Job

AddTask 添加待执行任务的实现

func (*Job) Do

func (j *Job) Do()

Do 开始执行作业

func (*Job) GetData

func (j *Job) GetData() DataMap

GetData 返回job上的DataSet

func (*Job) SetData

func (j *Job) SetData(dm DataMap) *Job

SetData 设置job上的DataSet

Jump to

Keyboard shortcuts

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