GithubHelp home page GithubHelp logo

olap's Introduction

class SalesData: def init(self, product, region, date, amount): self.product = product self.region = region self.date = date self.amount = amount

class OLAPModel: def init(self): self.sales_data = []

def add_sales_data(self, sales_data):
    self.sales_data.append(sales_data)

def get_sales_data(self):
    return self.sales_data

class OLAPProcessor: def init(self, olap_model): self.olap_model = olap_model

def total_sales_by_region(self):
    sales_data = self.olap_model.get_sales_data()
    result = {}
    for data in sales_data:
        if data.region not in result:
            result[data.region] = 0
        result[data.region] += data.amount
    return result

def total_sales_by_product(self):
    sales_data = self.olap_model.get_sales_data()
    result = {}
    for data in sales_data:
        if data.product not in result:
            result[data.product] = 0
        result[data.product] += data.amount
    return result

示例用法

olap_model = OLAPModel() olap_model.add_sales_data(SalesData("Product A", "Region 1", "2023-01-01", 100)) olap_model.add_sales_data(SalesData("Product B", "Region 2", "2023-01-02", 150)) olap_model.add_sales_data(SalesData("Product A", "Region 1", "2023-01-03", 200))

olap_processor = OLAPProcessor(olap_model) total_sales_by_region = olap_processor.total_sales_by_region() total_sales_by_product = olap_processor.total_sales_by_product()

print("Total Sales by Region:") print(total_sales_by_region) print("Total Sales by Product:") print(total_sales_by_product)

olap's People

Contributors

ethellawson 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.