Code Monkey home page Code Monkey logo

tool-api's Introduction

ARCHIVED

This project has been archived by Callum Snowden, as I'm working on a new version that is just all round "nicer".

tool-api

An 'API'/web interface for administering machines & users.

requirements

See "requirements.txt" for exact versions

  • Python3
  • Peewee (version greater than V3 - I am running V3.0.16)
  • Flask
  • PyMySQL
  • A MySQL server

how to run

The app is currently in development mode. To run,python3 run.py will start a server that listens on 0.0.0.0:5000 which will allow hardware to connect to the API.

database

The database has been dumped under the folder "db_dump" - this contains some test data that was used during development, and the database schema.

The file "models.py" will need to be changed to have the correct database connection string.

how do JSON?

Currently, the only endpoint that will return json is /canuse/<machineuid>/<cardid>

The format this expects is a GET request to the above URL, with the machine UID and card ID. This will return a JSON array with the format of [{"canuse": 0, "caninduct": 0}] which will change depending on the permissions of the user.

I plan on adding functionality to allow other endpoints to return JSON in the future, this is being developed on the /machines endpoint - if a GET request is made with a Accept header of application/json this will eventually return a JSON response.

tool-api's People

Contributors

adnbr avatar callumsnowden avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tool-api's Issues

Log entry & remote inductions implementation

Perhaps the "log" implementation could be as follows, with JSON POSTed to a new flask endpoint?

POST /logs/new

{
  "machineuid":"machine-uid",
  "carduid":"card-uid",
  "elapsed":x in seconds
}

The server assumes that the start time is x seconds prior to the submission time, to simplify the node programming (it's expected the Python server will know the time, but it's more of a pain to get time from NTP on the access node).

It would follow that the new permissions (from the induction) would be similar:

POST /permissions/new

{
  "machineuid":"machine-uid",
  "inductor":"inductor-card-uid",
  "inductee":"inductee-card-uid"
}

Where inductor-card-uid is the UID of a card which is canInduct = true and inductee-card-uid is presumably a UID of a card which is canUse = false for the current machine. Return 200 for all OK and inserted, or another status code for a failure? 403, "user cannot induct on this machine" for example.

The python side would create a new entry in the user table if it doesn't exist, with a generic username. Perhaps this can in future be updated from SPACEDATA.

Add support for cost calculations

Adding a "cost per minute" and "minimum charge" column to the machines table would allow automatic calculation of the cost to the user for machines (such as the laser cutter) which are chargeable by time used.

Do not allow duplicate permissions

Currently, duplicate permissions can be created which can cause issues. This needs to be fixed so that duplicate permissions cannot be created, and then return an error to the user.

Trigger ZoneMinder event on card insertion/removal

ZoneMinder includes the option for external triggers - a future enhancement could be to grab a frame or short clip at the start and end of each machine session.

Can be used to keep track of machine usage and evaluate state of machine when it is left. Would require an extra column in the machine table to track the ZM monitor that should be triggered.

There is the ability to overlay custom text, which could be the username or carduid, and the machinename currently in use.

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.