Example #1
0
 def load(self, filename):
     """
     Load the model
     """
     f = open(filename, "r")
     data = json.load(f)
     f.close()
     self.Nodes = data["Nodes"]
     self.W = [np.array(w) for w in data["W"]]
     self.B = [np.array(b) for b in data["B"]]
Example #2
0
 def save(self, filename):
     """
     Save the model to the file 'filename`.
     """
     data = {"Nodes": self.Nodes,
             "W": [w.tolist() for w in self.W],
             "B": [b.tolist() for b in self.B]}
     f = open(filename, "w")
     json.dump(data, f)
     f.close()
Example #3
0
 def InitTimezone(self):
     langlist = []
     f = open('/opt/installer/zone.csv')
     lines = f.read().split('\n')
     for line in lines:
         words = line.split("\"")
         if len(words) >= 5:
             langlist.append(words[5])
     langlist.sort()
     for lang in langlist:
         self.Timezone.Append(lang)
     f.close()
Example #4
0
 def loadBadCh(self):
     filename = os.path.join(self.pathName, 'Artifacts', 'badChannels.txt')
     if os.path.exists(filename):
         with open(filename) as f:
             badChannels = f.read()
             print 'Bad Channels : {}'.format(badChannels)
     else:
         os.mkdir(os.path.join(self.pathName, 'Artifcats'))
         with open(filename, 'w') as f:
             f.write('')
             f.close()
         badChannels = []
     return badChannels
Example #5
0
    def getSdbCsv(self,fileName):
        try:
            f = open(fileName, 'rb')
            reader = csv.reader(f)
            header = reader.next()

            for row in reader:
                car = Car()
                car.get_sdb_csv(row,header)
                self.cars[car.id] = car

        except csv.Error, e:
            f.close()
            sys.exit('file %s, line %d: %s' % (fileName, reader.line_num, e))
Example #6
0
 def updateDeviceList(self):
     if self.spectrometer:  #self.selected_model['iManufacturer']=='Seabreeze':
         functions.close(self.spectrometer)
     self.instr_list.clear()
     self.instr_list.addItem('Instruments:')
     self.device_models, self.device_list = functions.find_devices()
     for ii in range(1, (1 + len(self.device_models))):
         if self.device_models[str(
                 ii)]['idVendor'] + ':' + self.device_models[str(
                     ii)]['idProduct'] == '0xbd7:0xa012':
             self.device_name.append('StellarNet')
         else:
             self.device_name.append(
                 self.device_models[str(ii)]['idVendor'] + ':' +
                 self.device_models[str(ii)]['idProduct'])
         self.instr_list.addItem(self.device_name[ii - 1])
Example #7
0
    def writeCarsData2Csv(self, filename,data, mode,historyFile):
        global header
        #Es para que solo escriba la cabecera la primera vez
        if historyFile and os.path.isfile(filename):            
            header = False
            
        f = open(filename, mode)
        csvf = csv.DictWriter(f, Car.PARS.keys(), restval='', extrasaction='raise')
        
        if header:
            csvf.writeheader()

        for car in data.values():
            csvf.writerow(car.get_state_dict())
        f.close()
        
        
        header = True
Example #8
0
    def get_cars_from_csv(self,filename,repeated = False):
        try:
            f = open(filename, 'rb')
            reader = csv.reader(f)
            if header:
                reader.next()

            for row in reader:
                car = Car()
                car.get_from_csv(row)

                if repeated:
                    id = car.id+"_"+str(car.state['dtime'])
                    self.cars[id] = car                
                else:
                    self.cars[car.id] = car                
           
        except csv.Error, e:
            f.close()
            sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
Example #9
0
def handle_bar(timer, data, info, init_cash, transaction, detail_last_min,
               memory):
    if timer == 0:
        memory.status = 0  # -1, stop loss; 0, ready; 1, open

    position_new = detail_last_min[0]

    if memory.status == -1:
        if (timer - memory.stop_loss_time) % 120 == 0:
            memory.status = 0
    elif memory.status == 0:  # ready to open

        grd = [0, 0]
        grd[0] = gradient(asset_index1, data)
        grd[1] = gradient(asset_index2, data)
        delta = grd[0] - grd[1]

        if abs(delta) > 3 * transaction:  # just to ensure interest

            current_trend = trend(asset_index1, asset_index2, grd,
                                  data)  # trend detection
            index = decision(delta, current_trend, asset_index1,
                             asset_index2)  # item decision
            operate_index = index[0]
            target_index = index[1]
            memory.operate_price = np.mean(data[operate_index, 0:3])
            memory.target_price = np.mean(data[target_index, 0:3])
            memory.operate_index = operate_index
            memory.target_index = target_index
            memory.operate_time = timer
            memory.trend = current_trend

            position_new = operation(data, detail_last_min, info,
                                     operate_index, transaction, current_trend,
                                     underwear)
            memory.position = position_new
            memory.top = detail_last_min[4] - underwear
            memory.total = detail_last_min[4]
            memory.status = 1
    else:
        memory.top = peak_update(detail_last_min, memory)
        if (detail_last_min[4] - memory.top) / memory.top < -0.1:  # stop loss
            position_new = np.zeros(13, dtype=np.int)
            memory.stop_loss_time = timer
            memory.status = -1
            print("stop loss")

        if close(detail_last_min, memory, timer, data):  # close out
            position_new = np.zeros(13, dtype=np.int)
            memory.status = 0
            if timer > 8300:
                print('deal')

    return position_new, memory
Example #10
0
 def stop(self):
     functions.close(self.spectrometer)
     self.goto_time_zero(self.axis)
Example #11
0
 def close_app(self):
     functions.close(self.spectrometer)  # closes window
     self.close()
Example #12
0
                car.get_from_csv(row)

                if repeated:
                    id = car.id+"_"+str(car.state['dtime'])
                    self.cars[id] = car                
                else:
                    self.cars[car.id] = car                
           
        except csv.Error, e:
            f.close()
            sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
            
        except IOError, e:
            return
        except StopIteration:            
            f.close()
            return
        return self.cars
    
    # """
    # Carga la lista de taxis en los diccionarios
    # """        
    def getCarsFromPreviousHist(self,rows):
        for row in rows:
            car = Car()
            car.get_from_csv(row)
            self.cars[car.id] = car
           
        return self.cars
    
Example #13
0
s_area=f.square_area(3,4)
print(s_area)

###############FILE HANDLING###############


import os
 if os.path.exists("C://python notes//aa.txt"):
    os.remove("C://python notes\\aa.txt")
 else:
    print("file does not exist")

###########
f=open("C://python notes\\a.txt","w")
f.write("adding some data to the file. ")
f.close()

f=open("C://python notes//a.txt","r")
print(f.readline())

f=open("C://python notes//a.txt","a")
f.write("Adding some more data!\n yes.")

f=open("C://python notes//a.txt","r")
print(f.readline())

import os
os.rmdir("C://python notes//AA")

import os
if os.path.exists("C://python notes//aa.txt"):