def table(self): """総理大臣のCSVファイルを基にしたテーブルから、HTMLページを基にするテーブルに変換して、それを応答する。""" html_table = table.Table('output') html_at = html_table.attributes() tuples = self._input_table.tuples() is_first = True for a_tuple in tuples: if is_first: is_first = False else: values = a_tuple.values() keys = a_tuple.attributes().keys() attributes = a_tuple.attributes() output = [] output.append(values[keys.index('no')]) output.append(values[keys.index('order')]) output.append(values[keys.index('_names')]) output.append(values[keys.index('kana')]) output.append(values[keys.index('period')]) output.append(self.compute_string_of_days(values[keys.index('period')])) output.append(values[keys.index('school')]) output.append(values[keys.index('party')]) output.append(values[keys.index('birth')]) output.append(self.compute_string_of_image(a_tuple)) output_tuple = tuple.Tuple(html_at, output) self._output_table.add(output_tuple) return self._output_table
def table(self): """総理大臣のCSVファイルを基にしたテーブルから、HTMLページを基にするテーブルに変換して、それを応答する。""" html_table = [] attributes = self._input_table.attributes() keys = attributes.keys() tuples = self._input_table.tuples() values = [] for index, a_tuple in enumerate(tuples): values = a_tuple.values() html_table.append([]) html_table[index].append(values[keys.index("no")]) html_table[index].append(values[keys.index("order")]) html_table[index].append(values[keys.index("names")]) html_table[index].append(values[keys.index("kana")]) html_table[index].append(values[keys.index("period")]) html_table[index].append( self.compute_string_of_days(values[keys.index("period")])) html_table[index].append(values[keys.index("school")]) html_table[index].append(values[keys.index("party")]) html_table[index].append(values[keys.index("birth")]) html_table[index].append(self.compute_string_of_image(a_tuple)) for row in html_table: self._output_table.add( tuple.Tuple(self._output_table.attributes(), row)) return self._output_table
def table(self): """ダウンロードしたCSVファイルを読み込んでテーブルを応答する。""" reader_list = io.IO().read_csv(self.csv_filename) input_table = table.Table('input') for a_list in reader_list: a_tuple = tuple.Tuple(input_table.attributes(), a_list) input_table.add(a_tuple) return input_table
def table(self): """ダウンロードしたCSVファイルを読み込んでテーブルを応答する。""" print "[Reader]tableの起動を確認" csv_table = table.Table('input') print "[Reader]ファイルネーム確認", self._csv_name #継承の確認 #test = super(Reader,self).test() #print test reader = super(Reader, self).read_csv(self._csv_name) #print reader for row in reader: csv_table.add(tuple.Tuple(csv_table.attributes(), row)) #print row return csv_table
if not (int(row[0]) == year and int(row[1]) == month): continue if int(str(row[3])[14:16]) != 0: continue if not support.double_contains(row[8], dict["nations"]): continue if "CA" in row[7]: continue current_date = datetime(int(row[0]), int(row[1]), int(row[2])) current_tuple = tuple.Tuple() current_tuple.nation = row[8] current_tuple.year = year current_tuple.day_in_year = current_date.timetuple( ).tm_yday current_tuple.hour = int(str(row[3])[11:13]) current_tuple.holiday = support.is_business_day( current_date, current_tuple.nation) current_tuple.date = current_date # checking if tuple's day already encountered found = False for value in tuples: if value == current_tuple: current_tuple = value found = True break
else: print("Usage: %s -m minPts -e eps" % sys.argv[0]) print(minPts) print(eps) ''' Read data ''' data = [] file = open("./compound.txt", "r") #i =0 for line in file: temp = line.split('\t') temp = list(map(float, temp)) temp.pop() data.append(tuple.Tuple(temp)) #i+=1 #if i==5000: break file.close() ''' Dbscan ''' print("start dbscan") dbscan = db.Dbscan(data,minPts,eps) clusters = dbscan.perform() print("start drawing") i = 0 print("Liczba klastrow = " + str(len(clusters)))
i += 1 file.close() means = data.mean(0) sd = [] for a in range(num_of_atributes): temp = 0 for r in range(num_of_records): temp += (data[r][a] - means[a])**2 sd.append(math.sqrt(temp / num_of_records)) for r in range(num_of_records): for a in range(num_of_atributes): data[r][a] = (data[r][a] - means[a]) / sd[a] data_set = [] for r in range(num_of_records): data_set.append(tuple.Tuple(data[r])) print(data_set[0].values) dbscan = db.Dbscan(data_set, minPts, eps) clusters = dbscan.perform() color = [ 'ro', 'go', 'bo', 'co', 'mo', 'yo', 'ko', 'wo', 'rs', 'gs', 'bs', 'cs', 'ms', 'ys', 'ks', 'ws', 'r^', 'g^', 'b^', 'c^', 'm^', 'y^', 'k^', 'w^', 'r*', 'g*', 'b*', 'c*', 'm*', 'y*', 'k*', 'w*' ] i = 0 print("Liczba klastrow = " + str(len(clusters))) for c in clusters: x = [] y = []