Code Monkey home page Code Monkey logo

dean's Introduction

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
}

dean's People

Contributors

gkzy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.