1
0
forked from tdwojak/Python2017

Homework#2

This commit is contained in:
s45162 2017-12-15 17:50:29 +01:00
parent e7c555cd6a
commit 00d565690f
8 changed files with 81 additions and 15 deletions

View File

@ -27,7 +27,10 @@ Zainstaluj bibliotekę ``weather-api`` (https://pypi.python.org/pypi/weather-api
* Korzystając z prognozy, znajdź dzień, w którym będzie najzimniej. Wypisz nazwę tygodnia (w języku polskim) i temperaturę w C.
**ćwiczenie 5**
Katalog scores zawiera 64 pliki tekstowe, które posiadają informacje o wysokości miary ``BLEU`` na różnych etapach trenowania modelu. Nazwa każdego pliku na postać ``model.iterXXXXXXX.npz.bleu``, gdzie ``XXXXXXX``, to liczba iteracji.Zawartość każdego pliku jest podobna i ma następującą formę: *BLEU = YY.YY, 44.4/18.5/9.3/5.0 (BP=1.000, ratio=1.072, hyp_len=45976, ref_len=42903)*, gdzie ``YY.YY`` to wartość miary ``BLEU``. Znajdź plik, który zawiera najwyższą wartość miary ``BLEU``.
Katalog scores zawiera 64 pliki tekstowe, które posiadają informacje o wysokości miary ``BLEU``
na różnych etapach trenowania modelu. Nazwa każdego pliku na postać ``model.iterXXXXXXX.npz.bleu``, gdzie ``XXXXXXX``,
to liczba iteracji.Zawartość każdego pliku jest podobna i ma następującą formę: *BLEU = YY.YY, 44.4/18.5/9.3/5.0 (BP=1.000,
ratio=1.072, hyp_len=45976, ref_len=42903)*, gdzie ``YY.YY`` to wartość miary ``BLEU``. Znajdź plik, który zawiera najwyższą wartość miary ``BLEU``.
* Wykorzystaj bibliotekę ``glob`` (https://docs.python.org/2/library/glob.html)
* Wyświetl tylko pełną nazwe pliku (wraz z ścieżką).

View File

@ -1,3 +1,3 @@
print(id([3,5]))
print(id('kot'))
print(id(3.25))
print(id((1/3)))

View File

@ -1,15 +1,10 @@
def Fib(n):
i=n+2
if (n==0):
yield 1
if (n==1):
yield 1
else:
for i in range(n):
yield i
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
for c in Fib(5):
for c in Fib(7):
print(c)
##(``F(0)=1, F(1)=1, FN=F(N-1) + F(N-2)``).

5
labs03/task03.py Normal file
View File

@ -0,0 +1,5 @@
# pip install --user requests
import requests
r = requests.get('https://api.fixer.io/latest', auth=('user', 'pass'))
jkursy=r.json()
print("EUR:PLN "+str(jkursy['rates']['PLN']))

20
labs03/task04.py Normal file
View File

@ -0,0 +1,20 @@
#pip install --user weather-api
from datetime import datetime
from weather import Weather
weather=Weather()
city="Poznan"
weather_city=weather.lookup_by_location(city)
print("Aktualna pogoda in "+city+" :", weather_city.condition().text())
def ftoC(t):
return round(5/9 * (t-32),3)
daymap={0:"Poniedziałek",1:"Wtorek",2:"Środa",3:"Czwartek",4:"Piątek",5:"Sobota",6:"Niedziela"}
tmin=[]
dates=[]
for item in weather_city.forecast():
dates.append(item.date())
tmin.append(ftoC(int(item.low())))
print("Minimana temperatura w dniach "+dates[0]+" - " + dates[-1]+ " to " + str(min(tmin)) +"C przewidywana na dzień "+ dates[tmin.index(min(tmin))] + " ("+daymap[datetime.strptime(dates[tmin.index(min(tmin))],'%d %b %Y').weekday()]+").")

8
labs03/task05.py Normal file
View File

@ -0,0 +1,8 @@
import glob,json
bleu={}
name=""
for i in glob.glob('scores/*'):
file=open(i,'r').read().replace(",","").split(" ")
bleu[i]=float(file[2])
print("Minimalna wartość BLEU znaleziona w pliku: " +min(bleu, key=bleu.get))

View File

@ -6,6 +6,3 @@ def is_numeric(lista):
if not(isinstance(x,float)) and not(isinstance(x,int)):
return False
return True
print(is_numeric([5,56]))

View File

@ -1,3 +1,41 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from task01 import *
class DimensionError(Exception):
def __init__(self, text):
self.text = text
def __str__(self):
return self.text
class Point:
def __init__(self, wspolrzedne):
if (is_numeric(wspolrzedne)):
self.wspolrzedne=wspolrzedne
else:
raise Exception("Non numerical coords")
def __len__(self):
return len(self.wspolrzedne)
def __str__(self):
return(str(self.wspolrzedne))
def to_string(self):
return str(self.wspolrzedne)
def __add__(self, other):
if len(self.wspolrzedne)!=len(other.wspolrzedne):
raise DimensionError("Elements have different dimensions!!1")
else:
return [i+j for (i,j) in zip(self.wspolrzedne,other.wspolrzedne)]
pt=Point([1,2])
print(len(pt))
print(str(pt))
print(pt.to_string())
pt2=Point([7,99])
print(pt+pt2)
pt3=Point([1,2,3])
print(pt+pt3)