def setBirthday(self, month, day, year): """sets self's birthday to birthDate""" self.birthday = datetime.data(year, month, day)
def loadMartDocs(self): file = open(os.path.join(FILE_PATH, 'metadati_MART.json'), 'r') docContent = StringIO(file.read()) docDict = json.load(docContent) #this dict will be updated with the content of docsDict file.close() # date variables dateSeparator = '/' i = 0 #get or create project for doc in docDict: i = i+1 try: d = Drawing.objects.get(segnatura = doc['segnatura']) except: # document not present segn = doc['segnatura'] if segn is None: segn = 'blank' d = Drawing(segnatura = segn) try: d.project = Project.objects.get(sigla = doc['progetto']) except: d.project = None d.archivio = doc['sigla_archivio'] #d.formato = doc['formato'] d.annotazioni = doc['annotazioni'] d.tecnica = doc['supporto'] d.supporto = doc['supporto'] d.tipo = doc['descrizione'] d.segnatura = doc['segnatura'] #d.strumento = doc['strumento'] #d.scala = doc['scala'] d.sigla_archivio = doc['sigla_archivio'] #d.multipli = doc['multipli'] #d.restauri = doc['restauri'] #d.formato_cornice = doc['formato_cornice'] #d.collocazione = doc['collocazione'] #d.conservazione = doc['conservazione'] #d.riproduzione = doc['riproduzione'] #d.cartigli = doc['cartigli'] # set date try: data = doc['data'] prec = doc['precisione'] day = '' month = '' year = '' dateDay = 0 dateMonth = 0 dateYear = 0 if data is not None: nDateElements = data.count(dateSeparator) if nDateElements + 1 == 3: # 3 date elements - i.e. dd/mm/yyyy day, sep, rest = data.partition(dateSeparator) month, sep, year = rest.partition(dateSeparator) if prec == 'year': day = '1' dateDay = None month = '1' dateMonth = None elif prec == 'month': day = '1' dateDay = None dateMonth = int(month) else: dateDay = int(day) dateMonth = int(month) dateYear = int(year) d.data = datetime.data(int(year), int(month), int(day)) d.dataDay = dateDay d.dataMonth = dateMonth d.dataYear = dateYear except Exception, e: # print e d.data = None d.dateDay = None d.dateMonth = None d.dateYear = None d.save() print ("documento salvato: " + str(i))
import datetime import numpy as np import matplotlib.pyplot as plt from hmmlearn.hmm import GaussianHMM import pandas as pd import pandas_datareader.data as pdd QUANDL_API_KEY = 'xxxxxxxxxxxx' start = datetime.data(1970, 9, 4) end = datatime.data(2016, 5, 17) stock_quotes = pdd.DataReader('WIKI/INTC', 'quandl', start, end, access_key=QUANDL_API_KEY) closing_quotes = np.array(stock_quotes['Close']) volumes = np.array(stock_quotes['Volume'])[1:] diff_percentages = 100.0 * np.diff(closing_quotes) / closing_quotes[:-1] training_data = np.column_stack([diff_percentages, volumes]) hmm = GaussianHMM(n_components=7, covariance_type='diag', n_iter=1000) hmm.fit(training_data) num_samples = 300 samples, _ = hmm.sample(num_samples) plt.figure() plt.title('Difference percentages')
nDateElements = data.count(dateSeparator) if nDateElements + 1 == 3: # 3 date elements - i.e. dd/mm/yyyy day, sep, rest = data.partition(dateSeparator) month, sep, year = rest.partition(dateSeparator) if prec == 'year': day = '1' dateDay = None month = '1' dateMonth = None elif prec == 'month': day = '1' dateDay = None dateMonth = int(month) else: dateDay = int(day) dateMonth = int(month) dateYear = int(year) d.data = datetime.data(int(year), int(month), int(day)) d.dataDay = dateDay d.dataMonth = dateMonth d.dataYear = dateYear except Exception, e: # print e d.data = None d.dateDay = None d.dateMonth = None d.dateYear = None d.save() print ("documento salvato: " + str(i))