Skip to content

Commit

Permalink
add new files too
Browse files Browse the repository at this point in the history
  • Loading branch information
hearues-zueke-github committed Oct 15, 2019
1 parent 3b9b7a9 commit 64e3505
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 2 deletions.
78 changes: 76 additions & 2 deletions create_graph_net_speed/graph_net_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def time_measure(f, args):
if __name__ == '__main__':
print('Hello World!')
with open('saved_rx_tx_2019.10.10_13:06:17.txt', 'r') as f:
# with open('saved_rx_tx_2019.10.10_13:13:22.txt', 'r') as f:
# with open('saved_rx_tx_2019.10.09_19:36:02.txt', 'r') as f:
lines = f.readlines()

Expand Down Expand Up @@ -95,7 +96,8 @@ def time_measure(f, args):

max_y = np.max((np.max(ys_speed_rxs), np.max(ys_speed_rxs)))
plt.xlim([-1, 60*60*24])
plt.ylim([0, max_y+0.5])
plt.ylim([0, 8.0])
# plt.ylim([0, max_y+0.5])

plt.title('Date Time Range\nFrom: {}\nTo: {}'.format(dts[0], dts[-1]))

Expand All @@ -118,7 +120,79 @@ def time_measure(f, args):
lgnd.legendHandles[0]._legmarker.set_markersize(8)
lgnd.legendHandles[1]._legmarker.set_markersize(8)

plt.savefig('speedtest_average_all_values_{}.png'.format(dt_str), dpi=dpi)



# create histogram_values
xs_sec_new = (xs_sec).astype(np.int)
# xs_sec_new = (xs_sec*10).astype(np.int)
x_ticks = 60*60*24
range_sec = 60
d_rx = {i: [] for i in range(-range_sec, x_ticks+range_sec)}
d_tx = {i: [] for i in range(-range_sec, x_ticks+range_sec)}
xs_sec_2 = np.array(list(range(0, x_ticks)))
# d_rx = {i: [] for i in range(-range_sec*10, x_ticks+range_sec*10)}
# d_tx = {i: [] for i in range(-range_sec*10, x_ticks+range_sec*10)}
# xs_sec_2 = np.array(list(range(0, x_ticks)))/10

for x, y_rx, y_tx in zip(xs_sec_new, ys_speed_rxs, ys_speed_txs):
d_rx[x].append(y_rx)
d_tx[x].append(y_tx)
if x<range_sec:
# if x<range_sec*10:
d_rx[x+x_ticks].append(y_rx)
d_tx[x+x_ticks].append(y_tx)
elif x>=x_ticks-range_sec:
# elif x>=x_ticks-range_sec*10:
d_rx[x-x_ticks].append(y_rx)
d_tx[x-x_ticks].append(y_tx)

# now calculate for each second +-range_sec the median!
ys_speed_rxs_median = []
ys_speed_txs_median = []
for x in range(0, x_ticks):
l_rx = []
l_tx = []
for i in range(-range_sec, range_sec, 1):
# for i in range(-range_sec*10, range_sec*10, 1):
l_rx.extend(d_rx[x+i])
l_tx.extend(d_tx[x+i])
ys_speed_rxs_median.append(np.median(l_rx))
ys_speed_txs_median.append(np.median(l_tx))


fig = plt.figure(figsize=(13, 8))

max_y = np.max((np.max(ys_speed_rxs), np.max(ys_speed_rxs)))
plt.xlim([-1, 60*60*24])
plt.ylim([0, 4.0])
# plt.ylim([0, max_y+0.5])

plt.title('Date Time Range (Median values of +-{} sec)\nFrom: {}\nTo: {}'.format(range_sec, dts[0], dts[-1]))

plt.xlabel('Time of day')
plt.ylabel('Download/Upload Speed [MiB/s]')

ax = plt.gca()
ax.yaxis.set_minor_locator(MultipleLocator(0.1))
plt.grid(b=True, which='minor', axis='y', color='k', linewidth=0.1, linestyle='-')
plt.grid(b=True, which='major', axis='x', color='k', linewidth=0.1, linestyle='-')

plt.xticks([i*60*60 for i in range(0, 25)], ['{:02}:00:00'.format(i) for i in range(0, 25)], rotation=60)
fig.subplots_adjust(left=0.06, bottom=0.14, right=0.98, top=0.91)

p_rxs = plt.plot(xs_sec_2, ys_speed_rxs_median, 'b.', markersize=0.5)[0]
p_txs = plt.plot(xs_sec_2, ys_speed_txs_median, 'g.', markersize=0.5)[0]

lgnd = plt.legend((p_rxs, p_txs), ('Download Speed (median +-{} sec) [MiB/s]'.format(range_sec), 'Upload Speed (median +-{} sec) [MiB/s]'.format(range_sec)), loc='upper right')

lgnd.legendHandles[0]._legmarker.set_markersize(8)
lgnd.legendHandles[1]._legmarker.set_markersize(8)

plt.savefig('speedtest_average_all_values_median_range_{}_sec_{}.png'.format(range_sec, dt_str), dpi=dpi)


# plt.savefig('speedtest_average_all_values_{}.eps'.format(dt_str))

# plt.show(block=False)
plt.savefig('speedtest_average_all_values_{}.png'.format(dt_str), dpi=dpi)
136 changes: 136 additions & 0 deletions math_numbers/approx_pi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#! /usr/bin/python3

# -*- coding: utf-8 -*-

import decimal
from decimal import Decimal
decimal.getcontext().prec = 80

import numpy as np

import matplotlib.pyplot as plt
plt.close("all")

PI = Decimal('3.14159265358979323846264338327950288419716939937510')
EPSILON = Decimal('1E-12')

def get_approx_pi_method_1(n):
dec_2 = Decimal(2)
ys = [dec_2]

y = dec_2
z = np.sqrt(dec_2)
y *= dec_2/z
ys.append(y)

for j in range(2, n+1):
z = np.sqrt(dec_2+z)
y *= dec_2/z
ys.append(y)

return ys


def get_approx_pi_method_2(n):
y1 = Decimal(0)
y2 = Decimal(0)
ys = []

for k in range(0, n+1):
y1 += (-1)**k*(Decimal(1)/5)**(2*k+1)/(2*k+1)
y2 += (-1)**k*(Decimal(1)/239)**(2*k+1)/(2*k+1)
y = 16*y1-4*y2
ys.append(y)

return ys


def get_approx_pi_method_3(n):
y = Decimal(0)
ys = []

for k in range(0, n+1):
y += 1/Decimal(16**k)*(Decimal(4)/(8*k+1)-Decimal(2)/(8*k+4)-Decimal(1)/(8*k+5)-Decimal(1)/(8*k+6))
ys.append(y)

return ys


def get_approx_pi_method_own_1(n):
y1 = Decimal(1)
y2 = Decimal(1)
ys = [y1/y2*2]

for k in range(1, n+1):
y1 += 1/Decimal(2*k-1)
y2 += 1/Decimal(2*k)
# y += 1/Decimal(16**k)*(Decimal(4)/(8*k+1)-Decimal(2)/(8*k+4)-Decimal(1)/(8*k+5)-Decimal(1)/(8*k+6))
y = y1/y2*2
# print("k: {}, y: {}".format(k, y))
ys.append(y)

return ys


def get_needed_n_with_epsilon_precision(ys, epsilon):
for i, y in enumerate(ys, 0):
if np.abs(y-PI)<epsilon:
break
return i


if __name__ == '__main__':
print("Real pi: {}".format(PI))

n = 30

ys1 = np.array(get_approx_pi_method_1(n))
ys2 = np.array(get_approx_pi_method_2(n))
ys3 = np.array(get_approx_pi_method_3(n))
ys_own_1 = np.array(get_approx_pi_method_own_1(100))

print("ys1[-1]: {}".format(ys1[-1]))
print("ys2[-1]: {}".format(ys2[-1]))
print("ys3[-1]: {}".format(ys3[-1]))
print("ys_own_1[-1]: {}".format(ys_own_1[-1]))


# find needed n for getting EPSILON precision!
n1 = get_needed_n_with_epsilon_precision(ys1, EPSILON)
n2 = get_needed_n_with_epsilon_precision(ys2, EPSILON)
n3 = get_needed_n_with_epsilon_precision(ys3, EPSILON)

print("Needed terms for approx method nr. 1: {}".format(n1))
print("Needed terms for approx method nr. 2: {}".format(n2))
print("Needed terms for approx method nr. 3: {}".format(n3))


# create the plot of the absolute differences with the real number pi
plt.figure()

plt.yscale('log')
plt.title('Absolute differences of\ndifferent approximations for pi')

xs1 = np.arange(0, len(ys1))
xs2 = np.arange(0, len(ys2))
xs3 = np.arange(0, len(ys3))

diff_ys1 = np.abs(ys1-PI)
diff_ys2 = np.abs(ys2-PI)
diff_ys3 = np.abs(ys3-PI)

p1 = plt.plot(xs1, diff_ys1, 'b.-')[0]
p2 = plt.plot(xs2, diff_ys2, 'g.-')[0]
p3 = plt.plot(xs3, diff_ys3, 'r.-')[0]

plt.plot((0, n), (EPSILON, EPSILON), 'k-', linewidth=0.5)

plt.legend((p1, p2, p3), ('Approx method nr. 1', 'Approx method nr. 2', 'Approx method nr. 3'))

plt.xlabel('n')
plt.ylabel('absolute difference')

plt.xlim([0, n])

# plt.show()
plt.savefig('absolute_differences.png')
59 changes: 59 additions & 0 deletions test_programs/adapt_sleep_for_better_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#! /usr/bin/python3

# -*- coding: utf-8 -*-

import time
import datetime
import os
import sys

from copy import deepcopy

sys.path.append("../combinatorics/")
import different_combinations as combinations
sys.path.append("../math_numbers/")
from prime_numbers_fun import get_primes

# from time import time
from functools import reduce

from PIL import Image

import numpy as np

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter, AutoMinorLocator

sys.path.append("../")
from utils_serialization import get_pkl_gz_obj, save_pkl_gz_obj

if __name__ == '__main__':
print('Hello World!')

dt_prev = datetime.datetime.now()

sleep_seconds_should = 0.1
sleep_seconds = sleep_seconds_should-0.00038123
cummulative_error_seconds = 0
time.sleep(sleep_seconds)
lst_diff = []
for i in range(0, 1000):
# while True:
dt_now = datetime.datetime.now()
print("sleep_seconds {}".format(sleep_seconds))
print("dt_prev {}".format(dt_prev))
print("dt_now {}".format(dt_now))
diff = (dt_now-dt_prev).total_seconds()
print("diff {}".format(diff))
lst_diff.append(diff)
# if cummulative_error_seconds>0.01:
# # if diff>sleep_seconds_should:
# sleep_seconds *= 0.999
# elif cummulative_error_seconds<-0.01:
# sleep_seconds *= 1.001
cummulative_error_seconds += diff-sleep_seconds_should
print("cummulative_error_seconds {}".format(cummulative_error_seconds))
time.sleep(sleep_seconds)
dt_prev = dt_now

print("np.mean(lst_diff) {}".format(np.mean(lst_diff)))

0 comments on commit 64e3505

Please sign in to comment.