Giter VIP home page Giter VIP logo

pf's Introduction

pf

pf is a (for now) a command line tool that let's you turn sentences into structured data of any format you want by using a simple parser syntax.

Let's say you have a fabric store, a physical fabric store, and you want to keep track of all your finances and inventory. The only information you have are the raw facts that happened at your store, as they happen, and that's the only thing you need. So imagine that during the day you'll add facts like the following:

pf facts add 'sold 2m of cashmere for 104 bucks'
pf facts add 'sold 4m of wool for 150 bucks'
pf facts add 'got 100m of cashmere delivered'
pf facts add 'paid 200 to cashmere supplier'
pf facts add 'sold 6m of cashmere for 312 bucks'
pf facts add 'paid 250 to employee Maria'

After that (or before, it doesn't matter) you would define rules (by calling pf rules add or pf rules edit) to handle the 3 kinds of facts listed above with patterns somewhat like

'sold <quantity:number>m of <fabric:words> for <amount:money> bucks'
'got <quantity:number>m of <fabric:words> delivered'
'paid <amount:money> to <whom:words>'

When you call pf compute each fact is run, in order, through each available pattern and, if matched, the rule script is run. Each rule script receive the parameters captured in the fact parsing and the fact timestamp and can read and modify the current state (which begins as an empty JSON object {} by default). So for the "sold ..." rule you would perhaps

  • add the sale data to a big list of sales
  • add the value to your cash balances
  • subtract the sold items from your inventory

for the "got ..." rule you would

  • add the received items to the inventory

and for the "paid ..." rule you would

  • subtract the paid value from the cash balances
  • if the value was paid to an employee, keep track of your payments to that employee

Then you end up with a JSON object with all the data you need and you can use different tools, like jq, to crunch the data and produce reports, charts, prints and other useful stuff.

{
  "days": {
    "2018-02-30": {
      "sales": [
        {
          "item": "cashmere",
          "q": 2,
          "amount": 104
        },
        {
          "item": "wool",
          "q": 4,
          "amount": 150
        },
        {
          "item": "cashmere",
          "q": 6,
          "amount": 312
        }
      ],
      "payments": [
        {
          "target": "cashmere supplier",
          "amount": 200
        },
        {
          "target": "maria",
          "amount": 250
        }
      ],
      "balance": 116
    }
  },
  "inventory": {
    "cashmere": 177,
    "wool": 328
  },
  "employees": {
    "maria": {
      "monthly_payments": {
        "2018-02": [
          200,
          250 
        ] 
      },
      "outstanding_balance": 550
    } 
  }
}

If you decide later to start keeping track of things in a different way or to change your schema entirely, you just have to rewrite your rules, the facts will continue to be the same.

install

npm install -g pf-cli

This is an idea under development. The CLI program works, but much more functionality will be added yet, most notoriously:

  • incremental computing of facts
  • initial data loading and checkpoint saving
  • better logs and rule debugging helpers
  • PouchDB sync
  • a web client, at least for fact inputting, so normal people can use it on predefined schemas
  • fact input autosuggest based on the rule patterns structure

pf's People

Contributors

fiatjaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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