Skip to content

Instantly share code, notes, and snippets.

@pietrocolombo
pietrocolombo / duplicated_contacts.py
Created March 18, 2021 17:23
Delete duplicate contacts and contacts with more or less than 13 digits
import pandas as pd
contacts = pd.read_csv("contacts.csv")
contacts.drop_duplicates(subset=['Numero di telefono']) # name of the column that identifies the telephone number
# clears numbers that have more than 13 digits
index_to_drop = contacts[contacts['Numero di telefono'].map(len) != 13].index
contacts.drop(index_to_drop, inplace=True)
@pietrocolombo
pietrocolombo / AAL_make_mean_variance.py
Created April 26, 2021 07:57
Mean and std on 8 subsequent rows on roll, pitch e module parameters of every accelerometer. Dataframe has been splitted by class and by user
def make_mean_variance(dataframe):
new_row = {}
for field in ['user', 'gender', 'age', 'how_tall_in_meters', 'weight', 'body_mass_index', 'class']:
new_row[field] = dataframe[field].iloc[0]
for field in ['roll1', 'pitch1', 'roll2', 'pitch2', 'roll3', 'pitch3','roll4', 'pitch4']:
new_row[field] = np.var(dataframe[field])
for i in range (1, 5):
counting = {}
for activity in df['class'].unique():
counting[activity] = {}
activity_df = df[df['class'] == activity]
n_instance = activity_df.shape[0]
for user in df['user'].unique():
counting[activity][user] = activity_df[activity_df['user'] == user].shape[0]/n_instance*100
bars = []
@pietrocolombo
pietrocolombo / example_bot_telegam_no_library.py
Created July 3, 2021 13:17
Example of a telegram bot in python without using specific libraries
import json
import requests
import urllib
TOKEN = ""
URL = "https://api.telegram.org/bot{}/".format(TOKEN)
USERNAME_BOT = ""
@pietrocolombo
pietrocolombo / Extract frame.py
Last active January 13, 2022 07:23
Extract frame from a video
import cv2
import os
# Read the video from specified path
cam = cv2.VideoCapture("/content/gdrive/MyDrive/Foto & Video/2021/Casargo/Volo 2/DJI_0049.MP4")
try:
# creating a folder named data
if not os.path.exists('/content/gdrive/MyDrive/Foto & Video/2021/Casargo/Volo 2/DJI_0049'):
class DataDevice(Resource):
def put(self):
""" it receives the data from the devices and puts them in the database
:return:
"""
args = device_data_put_args.parse_args()
# check if the device exist
device = Device.query.get(args['id_device'])
if device is None:
@pietrocolombo
pietrocolombo / generation_pdf.py
Created December 22, 2022 22:25
example generation pdf (invoice) with reportlab
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.enums import TA_LEFT, TA_CENTER
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Paragraph
# pip install opencv-python
import cv2
import queue
import threading
import time
class Video(threading.Thread):
def __init__(self, camera, interval, path) -> None:
threading.Thread.__init__(self)
self._cam = cv2.VideoCapture(camera)
@pietrocolombo
pietrocolombo / optimization.py
Created July 22, 2024 20:47
optimization class for pygmo
class optimization:
def __init__(self, enc_vector, gps_vector, ratio_t2ml, ratio_t2mr,
abs_zero_initial, abs_first_coef, abs_second_coef, abs_third_coef,
abs_first_exp, abs_second_exp, abs_third_exp, orientation_start):
self.enc_vector = enc_vector
self.gps_vector = gps_vector
self.ratio_t2ml = ratio_t2ml
self.ratio_t2mr = ratio_t2mr
x y stamp
0 0 1600094165.564021110
0.00191943 0.00185668 1600094165.713231086
0.0104502 0.023996 1600094165.766628980
0.0177098 0.0451626 1600094165.864341974
0.0281736 0.0672945 1600094165.969501018
0.036788 0.0944362 1600094166.078454017
0.0498157 0.131995 1600094166.185786008
0.0735075 0.186108 1600094166.265960931
0.10357 0.265083 1600094166.364769935