Git Product home page Git Product logo

hsldatafetchexample's Introduction

SanomaPythonTest

Assignment for the Junior Data Engineer position at Sanoma. main.py contains comments.

Instructions

Run the script from a terminal by being in the project directory and running the command: python main.py The CSV will be saved in the working directory.

Docker

If running via Docker run the runCSV.bat OR use the commands below:

docker build -t pythontest .

docker run --name pythontest --mount source=pythonTestVol,target=/app pythontest <- This will save the csv into a volume named pythonTestVol

If you don't want to get access to the csv file simply run the run.bat file OR use the commands below:

docker build -t pythontest .

docker run pythontest

Dependencies

requests

pandas

datetime

os

Script explanation

getData()

Fetches the data for March 2020 by generating a range of dates and iterating through them. One call per iteration. Responses are stored in a list. Checks that the response contains something, filtering out days when the train doesn't run.

normalizeData()

Normalizes the data using normalize from Pandas. Handling of the nested list "timetableRows" by first exploding it and then applying putting it back into individual columns.

saveToCsv()

Saves the normalized data to a .csv in the working directory.

!!!If running via Docker, the file has to be stored in a volume(check instructions).!!!

avgActualArrivalTime()

Calculate the average actual arrival time at the end station.

  1. Filter for arrivals at end station HKI
  2. Define variable for storing arrival times as timedelta. timedelta makes it simple to do calculations on time.
  3. Split the string to get rid of the empty milliseconds fields and the timezone indicator Z and the days & years
  4. Convert the string to timedelta, including microseconds for a more accurate average
  5. Sum up the arrival times
  6. Calculate the average arrival time by dividing the sum with the amount of arrivals

hsldatafetchexample's People

Contributors

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