przyklady
This commit is contained in:
34
dzien_03/przyklady/fake_data.py
Normal file
34
dzien_03/przyklady/fake_data.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
'address', 'administrative_unit', 'am_pm', 'android_platform_token', 'ascii_company_email', 'ascii_email', 'ascii_free_email', 'ascii_safe_email', 'bank_country', 'bban', 'binary', 'boolean', 'bothify', 'bs', 'building_number', 'cache_pattern', 'catch_phrase', 'century', 'chrome', 'city', 'city_prefix', 'city_suffix', 'color', 'color_name', 'company', 'company_email', 'company_suffix', 'coordinate', 'country', 'country_calling_code', 'country_code', 'credit_card_expire', 'credit_card_full', 'credit_card_number', 'credit_card_provider', 'credit_card_security_code', 'cryptocurrency', 'cryptocurrency_code', 'cryptocurrency_name', 'csv', 'currency', 'currency_code', 'currency_name', 'currency_symbol', 'current_country', 'current_country_code', 'date', 'date_between', 'date_between_dates', 'date_object', 'date_of_birth', 'date_this_century', 'date_this_decade', 'date_this_month', 'date_this_year', 'date_time', 'date_time_ad', 'date_time_between', 'date_time_between_dates', 'date_time_this_century', 'date_time_this_decade', 'date_time_this_month', 'date_time_this_year', 'day_of_month', 'day_of_week', 'del_arguments', 'dga', 'domain_name', 'domain_word', 'dsv', 'ean', 'ean13', 'ean8', 'ein', 'email', 'factories', 'file_extension', 'file_name', 'file_path', 'firefox', 'first_name', 'first_name_female', 'first_name_male', 'first_name_nonbinary', 'fixed_width', 'format', 'free_email', 'free_email_domain', 'future_date', 'future_datetime', 'generator_attrs', 'get_arguments', 'get_formatter', 'get_providers', 'hex_color', 'hexify', 'hostname', 'http_method', 'iana_id', 'iban', 'image', 'image_url', 'internet_explorer', 'invalid_ssn', 'ios_platform_token', 'ipv4', 'ipv4_network_class', 'ipv4_private', 'ipv4_public', 'ipv6', 'isbn10', 'isbn13', 'iso8601', 'items', 'itin', 'job', 'json', 'language_code', 'language_name', 'last_name', 'last_name_female', 'last_name_male', 'last_name_nonbinary', 'latitude', 'latlng', 'lexify', 'license_plate', 'linux_platform_token', 'linux_processor', 'local_latlng', 'locale', 'locales', 'localized_ean', 'localized_ean13', 'localized_ean8', 'location_on_land', 'longitude', 'mac_address', 'mac_platform_token', 'mac_processor', 'md5', 'military_apo', 'military_dpo', 'military_ship', 'military_state', 'mime_type', 'month', 'month_name', 'msisdn', 'name', 'name_female', 'name_male', 'name_nonbinary', 'nic_handle', 'nic_handles', 'null_boolean', 'numerify', 'opera', 'paragraph', 'paragraphs', 'parse', 'password', 'past_date', 'past_datetime', 'phone_number', 'port_number', 'postalcode', 'postalcode_in_state', 'postalcode_plus4', 'postcode', 'postcode_in_state', 'prefix', 'prefix_female', 'prefix_male', 'prefix_nonbinary', 'pricetag', 'profile', 'provider', 'providers', 'psv', 'pybool', 'pydecimal', 'pydict', 'pyfloat', 'pyint', 'pyiterable', 'pylist', 'pyset', 'pystr', 'pystr_format', 'pystruct', 'pytimezone', 'pytuple', 'random', 'random_choices', 'random_digit', 'random_digit_not_null', 'random_digit_not_null_or_empty',
|
||||
"""
|
||||
|
||||
from faker import Faker
|
||||
from random import randint
|
||||
# import faker
|
||||
import csv
|
||||
|
||||
# fake_data = Faker(["pl_PL", 'en_US', 'ja_JP'])
|
||||
fake_data = Faker("pl_PL")
|
||||
|
||||
with open("dane.csv", "w", newline="") as plik:
|
||||
for _ in range(10):
|
||||
line = fake_data.name() + "," + fake_data.email() + "," + \
|
||||
fake_data.credit_card_number() + "," + fake_data.company() + "," + \
|
||||
fake_data.ios_platform_token() + "," + fake_data.postcode() + "\n"
|
||||
print(line)
|
||||
plik.write(line)
|
||||
|
||||
# generujemy listę list dla metody writerows
|
||||
fake_data_all = []
|
||||
for _ in range(3000):
|
||||
wydatki = randint(500, 1000)
|
||||
przychody = randint(5000, 15000)
|
||||
one_row = [fake_data.name(), fake_data.email(), \
|
||||
fake_data.credit_card_number(), wydatki, przychody]
|
||||
fake_data_all.append(one_row)
|
||||
|
||||
with open("dane2.csv", "w", newline="") as plik_csv:
|
||||
dane_writer = csv.writer(plik_csv, delimiter=",", \
|
||||
quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
|
||||
# dane_writer.writerow([fake_data.name(), fake_data.email()])
|
||||
dane_writer.writerows(fake_data_all)
|
||||
25
dzien_03/przyklady/r3_00.py
Normal file
25
dzien_03/przyklady/r3_00.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# program r3_00.py
|
||||
# Pierwsze wczytywanie danych i walidacja
|
||||
|
||||
# Definiujemy funkcję wczytującą dane
|
||||
def read_datas():
|
||||
h_start = input("Teraz podaj wysokość początkową (w m): ")
|
||||
v_start = input("Teraz podaj prędkość początkową (w m/sek) :")
|
||||
|
||||
if h_start < 10:
|
||||
print("Niestety, wysokość zbyt niska (min. 10 m)!")
|
||||
return None
|
||||
|
||||
if v_start < 2:
|
||||
print("Niestety, prędkość początkowa zbyt niska (min. 2 m/s)!")
|
||||
return None
|
||||
|
||||
return (h_start, v_start)
|
||||
|
||||
|
||||
initial_values = None
|
||||
while initial_values is None:
|
||||
print("Proszę, podaj dane niezbędne do wygenerowania wykresu.")
|
||||
initial_values = read_datas()
|
||||
|
||||
print("OK, dane początkowe wczytane - działamy dalej.")
|
||||
25
dzien_03/przyklady/r3_00_float.py
Normal file
25
dzien_03/przyklady/r3_00_float.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# program r3_00_float.py
|
||||
# Pierwsze wczytywanie danych i walidacja
|
||||
|
||||
# Definiujemy funkcję wczytującą dane
|
||||
def read_datas():
|
||||
h_start = float(input("Teraz podaj wysokość początkową (w m): "))
|
||||
v_start = float(input("Teraz podaj prędkość początkową (w m/sek) :"))
|
||||
|
||||
if h_start < 10:
|
||||
print("Niestety, wysokość zbyt niska (min. 10 m)!")
|
||||
return None
|
||||
|
||||
if v_start < 2:
|
||||
print("Niestety, prędkość początkowa zbyt niska (min. 2 m/s)!")
|
||||
return None
|
||||
|
||||
return (h_start, v_start)
|
||||
|
||||
|
||||
initial_values = None
|
||||
while initial_values is None:
|
||||
print("Proszę, podaj dane niezbędne do wygenerowania wykresu.")
|
||||
initial_values = read_datas()
|
||||
|
||||
print("OK, dane początkowe wczytane - działamy dalej.")
|
||||
48
dzien_03/przyklady/r3_00_read.py
Normal file
48
dzien_03/przyklady/r3_00_read.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# program r3_00_read.py
|
||||
# Pierwsze wczytywanie danych i walidacja - funkcja read_datas ostateczna
|
||||
|
||||
|
||||
# Definiujemy funkcję wczytującą dane
|
||||
def read_datas():
|
||||
def float_input(user_info, user_prompt, min_value):
|
||||
print("---[ wczytujemy dane]------------")
|
||||
print(user_info)
|
||||
user_input = input(user_prompt)
|
||||
if user_input.count(".") > 1:
|
||||
return None
|
||||
|
||||
if not user_input.replace(".", "").isdecimal():
|
||||
return None
|
||||
|
||||
user_value = float(user_input)
|
||||
if user_value < min_value:
|
||||
print(f"Wartość {user_value} jest mniejsza niż oczekiwana {min_value}.")
|
||||
return None
|
||||
return user_value
|
||||
|
||||
h_start = None
|
||||
v_start = None
|
||||
|
||||
while h_start is None:
|
||||
h_start = float_input(
|
||||
"Brak poprawnej wartości dla h_start. Typ float (np: 3.14)",
|
||||
"Teraz podaj wysokość początkową (w m, min. 10): ",
|
||||
10,
|
||||
)
|
||||
|
||||
while v_start is None:
|
||||
v_start = float_input(
|
||||
"Brak poprawnej wartości dla v_start. Typ float (np: 3.14)",
|
||||
"Teraz podaj prędność początkową (w m/sek, min. 2) :",
|
||||
2,
|
||||
)
|
||||
|
||||
return (h_start, v_start)
|
||||
|
||||
|
||||
initial_values = None
|
||||
while initial_values is None:
|
||||
print("Proszę, podaj dane niezbędne do wygenerowania wykresu.")
|
||||
initial_values = read_datas()
|
||||
|
||||
print("OK, dane początkowe wczytane - działamy dalej.")
|
||||
69
dzien_03/przyklady/r3_01.py
Normal file
69
dzien_03/przyklady/r3_01.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# program r3_01.py
|
||||
# Obliczenia danych do wykresu
|
||||
# Podstawowy rysunek miejsca startu i spadku
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Definiujemy funkcję wczytującą dane
|
||||
def read_datas():
|
||||
def float_input(user_info, user_prompt, min_value):
|
||||
print("---[ wczytujemy dane]------------")
|
||||
print(user_info)
|
||||
user_input = input(user_prompt)
|
||||
if user_input.count(".") > 1:
|
||||
return None
|
||||
|
||||
if not user_input.replace(".", "").isdecimal():
|
||||
return None
|
||||
|
||||
user_value = float(user_input)
|
||||
if user_value < min_value:
|
||||
print(f"Wartość {user_value} jest mniejsza niż oczekiwana {min_value}.")
|
||||
return None
|
||||
return user_value
|
||||
|
||||
h_start = None
|
||||
v_start = None
|
||||
|
||||
while h_start is None:
|
||||
h_start = float_input(
|
||||
"Brak poprawnej wartości dla h_start. Typ float (np: 3.14)",
|
||||
"Teraz podaj wysokość początkową (w m, min. 10): ",
|
||||
10,
|
||||
)
|
||||
|
||||
while v_start is None:
|
||||
v_start = float_input(
|
||||
"Brak poprawnej wartości dla v_start. Typ float (np: 3.14)",
|
||||
"Teraz podaj prędność początkową (w m/s, min. 2) :",
|
||||
2,
|
||||
)
|
||||
|
||||
return (h_start, v_start)
|
||||
|
||||
|
||||
initial_values = None
|
||||
while initial_values is None:
|
||||
print("Proszę, podaj dane niezbędne do wygenerowania wykresu.")
|
||||
initial_values = read_datas()
|
||||
|
||||
print("OK, dane początkowe wczytane - działamy dalej.")
|
||||
|
||||
# Rozpakowywanie tupli
|
||||
H_START, V_START = initial_values
|
||||
|
||||
# Obliczamy najważniejsze wartości
|
||||
|
||||
g = 9.81 # m/s^2
|
||||
total_time = ((2 * H_START) / g) ** (1 / 2)
|
||||
max_range = V_START * total_time
|
||||
|
||||
# Dodajemy wykres i umieszczamy punkt startu i spadku
|
||||
title = f"""Wykres rzutu poziomego z V_START = {V_START} m/s (g = {g} m/s^2)
|
||||
Czas lotu = {round(total_time,4)} s."""
|
||||
plt.scatter(0, H_START, label=f"H_START={H_START} m")
|
||||
plt.scatter(max_range, 0, label=f"max_range={round(max_range,3)} m")
|
||||
plt.grid()
|
||||
plt.title(title)
|
||||
plt.legend()
|
||||
plt.show()
|
||||
77
dzien_03/przyklady/r3_02.py
Normal file
77
dzien_03/przyklady/r3_02.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# program r3_02.py
|
||||
# Pełny wykres
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
# Definiujemy funkcję wczytującą dane
|
||||
def read_datas():
|
||||
def float_input(user_info, user_prompt, min_value):
|
||||
print("---[ wczytujemy dane]------------")
|
||||
print(user_info)
|
||||
user_input = input(user_prompt)
|
||||
if user_input.count(".") > 1:
|
||||
return None
|
||||
|
||||
if not user_input.replace(".", "").isdecimal():
|
||||
return None
|
||||
|
||||
user_value = float(user_input)
|
||||
if user_value < min_value:
|
||||
print(f"Wartość {user_value} jest mniejsza niż oczekiwana {min_value}.")
|
||||
return None
|
||||
return user_value
|
||||
|
||||
h_start = None
|
||||
v_start = None
|
||||
|
||||
while h_start is None:
|
||||
h_start = float_input(
|
||||
"Brak poprawnej wartości dla h_start. Typ float (np: 3.14)",
|
||||
"Teraz podaj wysokość początkową (w m, min. 10): ",
|
||||
10,
|
||||
)
|
||||
|
||||
while v_start is None:
|
||||
v_start = float_input(
|
||||
"Brak poprawnej wartości dla v_start. Typ float (np: 3.14)",
|
||||
"Teraz podaj prędność początkową (w m/s, min. 2) :",
|
||||
2,
|
||||
)
|
||||
|
||||
return (h_start, v_start)
|
||||
|
||||
|
||||
initial_values = None
|
||||
while initial_values is None:
|
||||
print("Proszę, podaj dane niezbędne do wygenerowania wykresu.")
|
||||
initial_values = read_datas()
|
||||
|
||||
print("OK, dane początkowe wczytane - działamy dalej.")
|
||||
|
||||
# Rozpakowywanie tupli
|
||||
H_START, V_START = initial_values
|
||||
|
||||
# Obliczamy najważniejsze wartości
|
||||
|
||||
g = 9.81 # m/s^2
|
||||
total_time = ((2 * H_START) / g) ** (1 / 2)
|
||||
max_range = V_START * total_time
|
||||
|
||||
# Obliczamy kolejne wartości Y dla X co 1/100 ogólnego zasięgu
|
||||
x_points = np.arange(0, max_range, max_range / 100)
|
||||
y_points = H_START - ((g / 2) * (x_points / V_START) ** 2)
|
||||
|
||||
# dodajemy wykres i umieszczamy punkt startu i spadku
|
||||
title = f"""Wykres rzutu poziomego z V_START = {V_START} m/s (g = {g} m/s^2)
|
||||
Czas lotu = {round(total_time,4)} s."""
|
||||
|
||||
plt.scatter(0, H_START, label=f"H_START={H_START} m")
|
||||
plt.scatter(max_range, 0, label=f"max_range={round(max_range,3)} m")
|
||||
plt.plot(x_points, y_points, marker="+", color="red", label="Kolejne punkty rzutu.")
|
||||
plt.grid()
|
||||
plt.title(title)
|
||||
plt.xlabel("Odległość w metrach")
|
||||
plt.ylabel("Wysokość w metrach")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
5
dzien_03/przyklady/r3_import.py
Normal file
5
dzien_03/przyklady/r3_import.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# program r3_import.py
|
||||
#
|
||||
|
||||
# wykorzystujemy znany nam już moduł
|
||||
import matplotlib.pyplot as plt
|
||||
55
dzien_03/przyklady/simple_md.py
Normal file
55
dzien_03/przyklady/simple_md.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
Prosty skrypt generujący plik w formacie Markdown
|
||||
https://www.markdownguide.org/basic-syntax/
|
||||
"""
|
||||
|
||||
import subprocess # wywoływanie poleceń systemowych !!!
|
||||
import snakemd
|
||||
from snakemd import Paragraph, InlineText
|
||||
import pandas as pd
|
||||
|
||||
|
||||
df = pd.read_csv("dane_sprzedazowe.csv", sep=";")
|
||||
print(df)
|
||||
|
||||
doc = snakemd.new_doc("simple_md_file")
|
||||
|
||||
doc.add_header("To będzie tytuł", 3)
|
||||
doc.add_paragraph("Dzisiaj tworzymy dokument w MD")
|
||||
doc.add_horizontal_rule()
|
||||
my_par = """
|
||||
To jest długi tekst,
|
||||
może mieć wiele linijek....
|
||||
|
||||
I jest identyczny z tym, co piszemy ;-)
|
||||
"""
|
||||
doc.add_paragraph(my_par)
|
||||
doc.add_horizontal_rule()
|
||||
|
||||
# dodatnie paragrafu z tekstem Italic/Pochyłym
|
||||
doc.add_element(
|
||||
Paragraph(
|
||||
[InlineText("Test DataFrame", italics=True)]
|
||||
))
|
||||
# tworzymy listę list z wartości data frame
|
||||
data_sales = df.values.tolist()
|
||||
print(data_sales)
|
||||
table_header = ["**Rok**", "~~Sprzedaż kart 5GB~~", "*Sprzedaż Abonamentów*", "Światłowody"]
|
||||
# tworzymy tabelę z nagłówkiem i danymi
|
||||
doc.add_table(
|
||||
table_header,
|
||||
data_sales, )
|
||||
|
||||
doc.output_page()
|
||||
|
||||
# dodamy wywołanie pandoc'a
|
||||
# https://docs.python.org/3/library/subprocess.html#module-subprocess
|
||||
|
||||
# pandoc -o dokument.docx simple_md_file.md
|
||||
ret_code = None
|
||||
try:
|
||||
command = ["pandoc", "-o", "dokument.xlsx", "simple_md_file.md"]
|
||||
ret_code = subprocess.run(command, capture_output=True)
|
||||
print(f"Returned: {ret_code}")
|
||||
except:
|
||||
print(f"ERROR: {ret_code}")
|
||||
Reference in New Issue
Block a user