Skip to content

Instantly share code, notes, and snippets.

@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):
@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 / list.c
Last active April 14, 2021 19:04
functions to manage lists
#include <stdio.h>
#include <stdlib.h>
typedef struct listas {
int info;
struct listas * next;
} list_t;
int listlen (list_t *);
list_t * listaddhead (list_t *, int);
# let's add information to our dataset
start_time <- Sys.time()
# function to transform angles deg into radians
deg2rad <- function(deg) {(deg * pi) / (180)}
if(!require(geosphere)){
install.packages("geosphere")
library("geosphere")
}
# let's add information to our dataset
start_time <- Sys.time()
# function to transform angles deg into radians
deg2rad <- function(deg) {(deg * pi) / (180)}
if(!require(geosphere)){
install.packages("geosphere")
library("geosphere")
}
@pietrocolombo
pietrocolombo / delete_duplicate_file.py
Last active November 24, 2024 07:50 — forked from vinovator/checkDuplicates.py
Python script to merge or delete duplicate files from a folder
# delete_duplicate_file.py
# Python 3.8.6
"""
Given a folder, walk through all files within the folder and subfolders
and delete all file that are duplicates so you have only one copy of every file
The md5 checcksum for each file will determine the duplicates
"""
import os
import logging
import logging.handlers
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO, filename='log.log')
logger = logging.getLogger(__name__)
if(!require(corrplot)){
install.packages("corrplot")
library("corrplot")
}
if(!require(RGraphics)){
install.packages("RGraphics")
library("RGraphics")
}
if(!require(grid)){
install.packages("grid")
# query to OpenStreetMap or bing to obtain information on the state, city,
# region both on the starting and ending point of each route
if(!require(revgeo)){
install.packages("revgeo")
library("revgeo")
}
# I read the csv generated by the script compress_database.r
# from the n lines that identify me a path I get one line per path
# I load the csv that the add_feature_consistency.r script generated for me
perc_csv <- "dataset_with_add_features.csv"
dati <- read.csv(perc_csv, header = TRUE, sep =",", quote = "\"", dec = ".")
# we remove the file that generates this script
file.remove("dataset_compresso.csv")