Skip to content

Instantly share code, notes, and snippets.

View Digma's full-sized avatar

Gael Grosch Digma

View GitHub Profile
@Digma
Digma / pc-gamer-gaming-industry-layoff-plot-pandas-matplotlib.py
Created February 16, 2024 10:47
pc-gamer-gaming-industry-layoff-plot-pandas-matplotlib.py
import glob
import os
import pandas as pd
# Data from: https://publish.obsidian.md/vg-layoffs/Archive/2024
# The data is stored in a directory with one CSV per year. Change the directory name accordingly
path = './data/gaming-layoff/'
all_files = glob.glob(os.path.join(path, "*.csv")) # advisable to use os.path.join as this makes concatenation OS independent
# Load all the CSVs into a single dataframe
@Digma
Digma / ourworldindata_ghg_pandas.py
Last active February 5, 2024 16:56
Matplotlib Line Chart in the style of OurWorldInData
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Data from Our World in Data (https://ourworldindata.org/grapher/ghg-emissions-by-sector)
df = pd.read_csv('data/ghg-emissions-by-sector.csv')
df_grouped = (
df
.drop(columns=["Entity", "Code"])
@Digma
Digma / firebase-parking-status-update.py
Created May 1, 2019 11:20
Firebase updating parking status (taken parking spaces)
def updateSpaces(db, parking_id, spaces_taken):
doc_ref = db.collection(u'parklots').document(parking_id)
doc_ref.update({
u'occupied_parking_spaces': spaces_taken
})
@Digma
Digma / opencv-load.py
Created May 1, 2019 11:15
OpenCV load image, video or streams
parser.add_argument('--image', help='Path to image file.')
parser.add_argument('--video', help='Path to video file.')
parser.add_argument('--streaming', help='Path to video url')
def load_open_cv_capture(args):
if args.image:
# Open the image file
file_does_not_exist(args.image)
cap = cv.VideoCapture(args.image)
@Digma
Digma / is-car-parked.py
Last active May 1, 2019 10:05
Function to determine if the car is parked
def is_parked_car(bounding_box, bounding_boxes_history, current_frame_idx, look_at_past_n, detection_ratio):
"""
Determine if car is detected as parked
:param bounding_box: Tuple of pixel positions (left, top, right, bottom)
:param bounding_boxes_history: List of bounding box including frame number (frame_id, left, top, right, bottom)
:param current_frame_idx: Index of current frame
:param look_at_past_n: Number of frame to consider for classification
:param detection_ratio: Minimum ratio to classify a car as parked
:return: boolean
@Digma
Digma / matching-bounding-box.py
Last active May 1, 2019 10:05
Function used to detect matching bounding boxes using center position
def get_center_coords(bounding_box):
left, top, width, height = bounding_box
center_coord_y = int(left + width / 2.)
center_coord_x = int(top + height / 2.)
return center_coord_x, center_coord_y
def get_shortest_side_lenght(bounding_box):
@Digma
Digma / filter-car-classes-yolo.py
Created April 30, 2019 18:04
Filter car classes from YOLO output
def is_car(class_name):
return class_name in str(["car", "truck", "bus"])
@Digma
Digma / run-yolo.sh
Created April 30, 2019 17:59
Run yolo on set of images in folder
#!/usr/bin/env bash
for filename in $1/*; do
./darknet detect cfg/yolov3.cfg weights/yolov3.weights "$filename" -out "out_$(basename "$filename")"
done
@Digma
Digma / install-yolo.sh
Created April 30, 2019 17:58
Install YOLO bash script
#!/usr/bin/env bash
git clone https://github.com/sowson/darknet.git
cd darknet
make
mkdir -p weights
wget https://pjreddie.com/media/files/yolov3.weights -O ./weights/yolov3.weights
export GOPATH=$HOME/Go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then