def corr(directory, threshold): df = complete.complete(directory, [i for i in range(1, 333)]) # keeping track whether threshold has crossed or not id_list = df[df.nobs > threshold].id corr_list = [] for i in id_list: with open(directory + "/{0:03}.csv".format(i), newline='') as csvfile: reader = csv.reader(csvfile, delimiter='\n') # skip header file next(reader) sulfate_list = [] nitrate_list = [] for row in reader: items = row[0].split(",") if not items[1] == "NA" and not items[2] == "NA": sulfate_list.append(float(items[1])) nitrate_list.append(float(items[2])) val = round(np.corrcoef(sulfate_list, nitrate_list)[0][1], 5) corr_list.append(val) return corr_list
def do_get_proposals(self, context): insert = context.get_iter() buffer = insert.get_buffer() incomplete = self._get_incomplete_string(context, '_.') if (not incomplete) or incomplete.isdigit(): return completes = complete(buffer.get_text(*buffer.get_bounds()), incomplete, insert.get_line()) if not completes: return incomplete2 = self._get_incomplete_string(context, '_') def sortfunc(a, b): if a['abbr'].startswith('_'): return 1 if b['abbr'].startswith('_'): return -1 return a['abbr'] > b['abbr'] def makeitem(item): # discard chars after opening parenthesis tmp = item['abbr'].split('(') if len(tmp) == 1: tmp = tmp[0] elif len(tmp) == 2 and tmp[1] == ')': tmp = tmp[0] + '()' else: tmp = tmp[0] + '(' result = gsv.CompletionItem(item['abbr'], tmp) result.set_property('info', item['info']) return result return [makeitem(item) \ for item in sorted(completes, cmp=sortfunc) \ if item['abbr'].startswith(incomplete2)]
def display_completions(self, view, event): """Find completions and display them.""" doc = view.get_buffer() insert = doc.get_iter_at_mark(doc.get_insert()) start = insert.copy() while start.backward_char(): char = unicode(start.get_char()) if not self.re_alpha.match(char) and not char == ".": start.forward_char() break incomplete = unicode(doc.get_text(start, insert)) incomplete += unicode(event.string) if incomplete.isdigit(): return self.cancel() completes = complete( doc.get_text(*doc.get_bounds()), incomplete, insert.get_line()) if not completes: return self.cancel() self.completes = completes if "." in incomplete: incompletelist = incomplete.split('.') newword = incompletelist[-1] self.completions = list(x['abbr'][len(newword):] for x in completes) length = len(newword) else: self.completions = list(x['abbr'][len(incomplete):] for x in completes) length = len(incomplete) for x in completes: x['completion'] = x['abbr'][length:] window = gtk.TEXT_WINDOW_TEXT rect = view.get_iter_location(insert) x, y = view.buffer_to_window_coords(window, rect.x, rect.y) x, y = view.translate_coordinates(self.window, x, y) self.show_popup(completes, x, y)
def _display_completions(self, view, event): """Find completions and display them in the completion window.""" doc = view.get_buffer() insert = doc.get_iter_at_mark(doc.get_insert()) start = insert.copy() while start.backward_char(): char = unicode(start.get_char()) if not self._re_alpha.match(char) and not char == ".": start.forward_char() break incomplete = unicode(doc.get_text(start, insert)) incomplete += unicode(event.string) if incomplete.isdigit(): # Usually completing numbers is not a good idea. return self._terminate_completion() self._completes = complete( doc.get_text(*doc.get_bounds()), incomplete, insert.get_line()) if "." in incomplete: incompletelist = incomplete.split('.') newword = incompletelist[-1] #self.completions = list(x['abbr'][len(newword):] for x in completes) length = len(newword) if not length==0 : incomplete=newword else: #self.completions = list(x['abbr'][len(incomplete):] for x in completes) length = len(incomplete) self._incomplete_num=-length self._find_completions(doc, incomplete) if not self._completions: return self._terminate_completion() self._show_completion_window(view, insert)
def corr(directory, threshold): #open only those files whose nobs >threshold corrVect = [] d = complete(directory, id=range(1, 333)) for i in range(0, len(d)): if (d.loc[i]['nobs'] > threshold): n = d.loc[i]['id'] with open(directory + "/{num:0>3}.csv".format(num=str(n))) as csvfile: reader = csv.reader(csvfile, delimiter='\n') next(reader) sulf_vect = [] nit_vect = [] for row in reader: items = row[0].split(",") if (not items[1] == "NA" and not items[2] == "NA"): sulf_vect.append(float(items[1])) nit_vect.append(float(items[2])) c = np.corrcoef(sulf_vect, nit_vect) c = c[0][1] c = float("{0:.5f}".format(c)) corrVect.append(c) print(corrVect[:6])
def main(): A().display(title="Automate A", wait=False) B().display(title="Automate B", wait=False) comp_aut1 = complete.complete(A()) comp_aut2 = complete.complete(B()) comp_aut1.display(title="Automate A complete", wait=False) comp_aut2.display(title="Automate B complete", wait=False) # Test pour intersection. toto = intersection(comp_aut1, comp_aut2) # Test si l'automate retourné est bien l'intersection de A() par B() if type(toto) == str: print("AUTOMATE VIDE !") else: toto.display(title="A inter B", wait=False) # Test pour union. titi = union(comp_aut1, comp_aut2) titi.display(title="A union B", wait=False)
from complete import complete #from word_vectors import TfIdfEmbedding #print(dir()) complete("Book a meeting with Piyush for 2pm")
import redis from complete import build_set, complete r = redis.StrictRedis(host='1.1.1.2', port=6379, db=0) r.flushall() data = [] file = open('names', 'r') for name in file: data.append(name.strip("\n")) build_set(r, "tmp", data) print "Start Testing..." for name in data: results = complete(r, "tmp", name, 10) if results[0] != name: print "ERROR:", name, results #else: # print "CORRECT:", name, results