Giter Site home page Giter Site logo

9ssi7 / acc Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 14 KB

Go library for efficient data accumulation and processing.

Home Page: https://pkg.go.dev/github.com/9ssi7/acc

License: Apache License 2.0

Go 100.00%
data-aggregation data-processing go-library scheduled-tasks

acc's Introduction

Accumulator: A Go-based Data Accumulation Mechanism

Overview

Accumulator is a lightweight Go library designed to aggregate, manage, and process data items. Whether you're accumulating data from various sources, processing them at specific intervals, or simply managing a stream of data, this library provides the tools you need.

Features

  • Flexible Storage: Choose from built-in storage options like in-memory storage or integrate with your custom storage mechanism.
  • Customizable Processing: Define how data items are processed using your custom function.
  • Configurable Interval: Set the interval at which accumulated data is processed.
  • Scheduled Processing: Optionally start processing data at a specific time.

Installation

To install the package, simply run:

go get github.com/9ssi7/acc

Documentation

Go Reference

Flow Diagrams

Continuous Insert with DB Index Issues

graph TD;
    Start[Start] --> Insert1[Insert Data 1];
    Insert1 --> Insert2[Insert Data 2];
    Insert2 --> Insert3[Insert Data 3];
    Insert3 --> Insert4[Insert Data 4];
    Insert4 --> Insert5[Insert Data 5];
    Insert5 --> IndexBroken[Index Broken];
Loading

Using Accumulator for Batch Processing

graph TD;
    Start[Start] --> Accumulate[Accumulate Data];
    Accumulate --> Process[Process Data];
    Process --> Wait[Wait 15 Minutes];
    Wait --> Accumulate;
Loading

Usage

Basic Setup

Here's a basic example demonstrating how to set up an accumulator:

package main

import (
	"fmt"
	"time"

	"github.com/9ssi7/acc"
)

func main() {
	config := acc.Config[int]{
		Processor: processFunction,
		// ... other configurations
	}

	accumulator := acc.New(config)
	// Start using the accumulator
}

func processFunction(data []int) {
	// Your logic to process data
	fmt.Println("Processing data:", data)
}

Advanced Configurations

Using StartTime Configuration

To start the accumulator processing at a specific time, you can use the StartTime configuration. Below is an example demonstrating how to set a start time:

func main() {
	config := acc.Config[int]{
		Processor: processFunction,
		StartTime: time.Date(2024, time.December, 31, 23, 59, 0, 0, time.UTC), // Processing will start on New Year's Eve at 23:59
		// ... other configurations
	}

	accumulator := acc.New(config)
	// Start using the accumulator
}

Using Interval Configuration

To configure the interval at which accumulated data is processed, you can set the Interval configuration. Below is an example demonstrating how to set an interval:

func main() {
	config := acc.Config[int]{
		Processor: processFunction,
		Interval:  30 * time.Second, // Data will be processed every 30 seconds
		// ... other configurations
	}

	accumulator := acc.New(config)
	// Start using the accumulator
}

Starting the Accumulator Asynchronously

To start the accumulator asynchronously using a goroutine, you can use the following approach:

func main() {
    config := acc.Config[int]{
        Processor: processFunction,
        Interval:  30 * time.Second, // Data will be processed every 30 seconds
        // ... other configurations
    }

    accumulator := acc.New(config)

    // Start the accumulator in a goroutine
    go func() {
        if err := accumulator.Start(); err != nil {
            fmt.Println("Error starting accumulator:", err)
        }
    }()

    // You can continue with other operations or wait for user input to exit
    // For example:
    // fmt.Println("Press Ctrl+C to exit...")
    // select {}
}

By starting the accumulator in a goroutine, it will run in the background, allowing the main program flow to continue without interruption.

Contributing

We welcome contributions! Please see our Contribution Guidelines for details.

License

This project is licensed under the Apache License. See LICENSE for more details.

acc's People

Contributors

9ssi7 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

acc's Issues

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.