-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_trucks_num.py
92 lines (67 loc) · 3.04 KB
/
stats_trucks_num.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import pandas as pd
import numpy as np
import collections
from statistics import mean, median
from settings import settings
file1 = pd.read_csv(os.path.join(settings.csv_folder, "ams_trucks_num_13000.csv"))
trucks_num = file1.tot_trucks.to_list()
trucks_mean = mean(trucks_num)
trucks_median = median(trucks_num)
print("Numero medio di camion:", trucks_mean)
print("Numero mediano di camion:", trucks_median)
print("*"*50)
file2 = pd.read_csv(os.path.join(settings.csv_folder, "ams_trucks_load_yearly_13000.csv"))
load = file2.tot_weight.to_list()
load_mean = mean(load)
load_median = median(load)
print("Peso medio fine giro:", load_mean)
print("Peso mediano fine giro:", load_median)
print("*"*50)
trucks_load = pd.read_csv(os.path.join(settings.csv_folder, "ams_trucks_paths_yearly_13000.csv"))
trucks_load['tot_weight'] = trucks_load.groupby(['date', 'truck_num'])['weight'].transform('sum')
trucks_load = trucks_load.drop_duplicates(subset=['date', 'truck_num'], keep='last')
trucks_load = trucks_load[['date', 'truck_num', 'tot_weight']]
def percentage(part, whole):
percentage = round(100 * float(part)/float(whole), 2)
return str(percentage) + "%"
df = trucks_load
n_camions = len(trucks_load['tot_weight'])
print(df.describe(percentiles=[.25, .5, .75, .99]))
n_camion_carichi = len(df[df['tot_weight'] >= 9750])
print("\nNumero di camion carichi (peso ≥ 12000): " + str(n_camion_carichi) + ", Percentuale: " + str(percentage(n_camion_carichi, n_camions)))
n_camion_semi_carichi = len(df[(df['tot_weight'] < 9750) & (df['tot_weight'] >= 6500)])
print("Numero di camion semi-carichi (8000 ≤ peso < 12000): " + str(n_camion_semi_carichi) + ", Percentuale: " + str(percentage(n_camion_semi_carichi, n_camions)))
n_camion_semi_vuoti = len(df[(df['tot_weight'] < 6500) & (df['tot_weight'] >= 3250)])
print("Numero di camion semi-vuoti (4000 ≤ peso < 8000): " + str(n_camion_semi_vuoti) + ", Percentuale: " + str(percentage(n_camion_semi_vuoti, n_camions)))
n_camion_vuoti = len(df[df['tot_weight'] < 3250])
print("Numero di camion vuoti (peso < 4000): " + str(n_camion_vuoti) + ", Percentuale: " + str(percentage(n_camion_vuoti, n_camions)))
print("*"*50)
# Python program to count the frequency of
# elements in a list using a dictionary
def CountFrequency(my_list):
# Creating an empty dictionary
freq = {}
for items in my_list:
freq[items] = my_list.count(items)
my_dict = {}
for key, value in freq.items():
#print("% d : % d" % (key, value))
my_dict[key] = value
my_dict_items = my_dict.items()
sorted_items = sorted(my_dict_items)
sorted_items = dict(sorted_items)
sorted_items.pop(-120.0)
return sorted_items
my_list = load
a = CountFrequency(my_list)
measures = []
avg_weights = []
for key, value in a.items():
#print("Key:" +str(key) +", Value:" + str(value))
measures.append(key)
avg_weights.append(value)
measures_np = np.asarray(measures)
avg_weights_np = np.asarray(avg_weights)
media_pesata = np.average(measures_np, weights=avg_weights_np)
print("MEDIA PESATA:", media_pesata)