Skip to content

danielonodje/charge-usage-estimator

Repository files navigation

HOW TO RUN

Installation

Please set up the application by running npm run setup. This will install dependences, create the sqlite database, generate prisma client types, and run migrations.

I am using Node v22.10. If you run into any issues, please check that your node version is at least 20.

Simulation

The simulation can be run using npm run simulation. Running it will generate a json file containing the simulation output in the outputs folder.

Running npm run graph-concurrency-factor will run the simulation but vary the amount of chargepoints from 1 - 30. This will not produce a json file output but will create a png image in the outputs folder, showing how the concurrency factor behaves as the number of chargepoints changes

Backend

Running npm start will start a RURU GraphQL UI Server on port 4000. By opening that page in the browser, you can query the backend.

I have included sample queries in the Query Samples section below for convenience. Just copy and/or modify the query you want into the Ruru UI and click the run button.

Tech Choices

The application uses NodeJS with Typescript primarily. I'm using tsx as a typescript runtime.

For the database stack, I am using Prisma. I had originally intended to use Prisma with Postgres but that might have needed setting up a Docker container to run it. The simpler choice was Sqlite which Prisma supports of out the box.

The Backend is Express with GraphQL. I'm using Ruru to serve the GraphQL UI.

I'm using seedrandom.js for deterministic random number generation in the simulation.

Places of Interest

Query Samples

Create Simulation (Mutation)
mutation {
  simulate(input: {
    chargerCount: 20
    arrivalProbabilityMultiplier: 100
    consumptionPerKmKWH: 0.18
    chargerPowerOutputKW: 11
    totalTicks: 35040
  }) {
    input {
      chargerCount
      arrivalProbabilityMultiplier
      consumptionPerKmKWH
      chargerPowerOutputKW
      totalTicks
    }
    output {
      totalEnergyConsumed
      exemplaryDay {
        sampleDay {
          totalEnergyUsed
        }
        averageDay {
          totalEnergyUsed
        }
      }
      averageChargingEvents {
        perDay
        perWeek
        perMonth
        perYear
      }
      totalChargingEvents
      usage {
        day
        data {
          totalEnergyUsed
        }
      }
    }
  }
}
Get all Simulations (Query)
query {
  getSimulations {
    input {
      id
      chargerCount
      arrivalProbabilityMultiplier
      consumptionPerKmKWH
      chargerPowerOutputKW
      totalTicks
    }
    output {
      id
      totalEnergyConsumed
      totalChargingEvents
      averageChargingEvents {
        perDay
        perWeek
        perMonth
        perYear
      }
      exemplaryDay {
        sampleDay {
          totalEnergyUsed
        }
        averageDay {
          totalEnergyUsed
        }
      }
      usage {
        day
        data {
          totalEnergyUsed
        }
      }
    }
  }
}
Delete Simulation
mutation {
  deleteSimulation(inputId: 1)
}

The GraphQL Schema is in graphql/schema.ts if you'd like more details

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published