GithubHelp home page GithubHelp logo

green-software-foundation / if-plugin-template Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 3.0 357 KB

Template for creating custom plugins supported by `IF` framework.

Home Page: https://github.com/Green-Software-Foundation/if-plugin-template

License: MIT License

JavaScript 15.78% TypeScript 79.80% Shell 4.42%
green if impact software plugin

if-plugin-template's Introduction

if-plugin-template

if-plugin-template is an environmental impact calculator template which exposes an API for IF to retrieve energy and embodied carbon estimates.

Implementation

Here can be implementation details of the plugin. For example which API is used, transformations and etc.

Usage

To run the <YOUR-CUSTOM-PLUGIN>, an instance of PluginInterface must be created. Then, the plugin's execute() method can be called, passing required arguments to it.

This is how you could run the model in Typescript:

async function runPlugin() {
  const newPlugin = await new MyCustomPlugin().configure(params);
  const usage = await newPlugin.calculate([
    {
      timestamp: '2021-01-01T00:00:00Z',
      duration: '15s',
      'cpu-util': 34,
    },
    {
      timestamp: '2021-01-01T00:00:15Z',
      duration: '15s',
      'cpu-util': 12,
    },
  ]);

  console.log(usage);
}

runPlugin();

Testing model integration

Using local links

For using locally developed model in IF Framework please follow these steps:

  1. On the root level of a locally developed model run npm link, which will create global package. It uses package.json file's name field as a package name. Additionally name can be checked by running npm ls -g --depth=0 --link=true.
  2. Use the linked model in impl by specifying name, method, path in initialize models section.
name: plugin-demo-link
description: loads plugin
tags: null
initialize:
  plugins:
    my-custom-plugin:
      method: MyCustomPlugin
      path: "<name-field-from-package.json>"
      global-config:
        ...
...

Using directly from Github

You can simply push your model to the public Github repository and pass the path to it in your impl. For example, for a model saved in github.com/my-repo/my-model you can do the following:

npm install your model:

npm install -g https://github.com/my-repo/my-model

Then, in your impl, provide the path in the model instantiation. You also need to specify which class the model instantiates. In this case you are using the PluginInterface, so you can specify OutputModel.

name: plugin-demo-git
description: loads plugin
tags: null
initialize:
  plugins:
    my-custom-plugin:
      method: MyCustomPlugin
      path: https://github.com/my-repo/my-model
      global-config:
        ...
...

Now, when you run the manifest using the IF CLI, it will load the model automatically. Run using:

ie --manifest <path-to-your-impl> --output <path-to-save-output>

if-plugin-template's People

Contributors

jmcook1186 avatar mariamkhalatova avatar narekhovhannisyan avatar perkss avatar seanmcilroy29 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

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