Ejemplo n.º 1
0
    def get(self):
        get_data = blobstore.BlobInfo.all()
        fkey = get_data.fetch(get_data.count())
        for dat in range(0, get_data.count()):
            filekey = fkey[dat]

            wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
            v = addVesselData(wb, str(fkey[dat].filename).replace(" ", ""))
            # if not (v == ""):
            y = makeManifestPickle(wb)
            if y["header"] == "manifest":
                if not (models.Manifest().find_duplicate(y["vessel"], y["voyage"], y["port"])):
                    man = models.Manifest()
                    man.blob = filekey.key()
                    man.vessel_name = y["vessel"]
                    man.voyage = y["voyage"]
                    man.port = y["port"]
                    man.put()
                    #    					search.Index(name='Manifest').put(CreateDocument(y["vessel"], y["voyage"], y["port"], man))
                    # 	if y["vessel"]:
                    # 		search.Index(name='Manifest').put(CreateDocument(y["vessel"], y["voyage"], y["port"], str(man.key)))
                    for c in range(5, y["numrows"]):
                        SaveManifestDetail(man.key, y, c, man.vessel_name, man.voyage, man.port)
            else:
                y = "y"

        params = {"y": y}
        return self.render_template("testman.html", **params)
Ejemplo n.º 2
0
	def get(self):
		get_data = blobstore.BlobInfo.all()
		fkey = get_data.fetch(get_data.count())
		for dat in range(0, get_data.count()):
			filekey = fkey[dat]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
			y = makeManifestPickle(wb)
			if (y["header"] == "manifest"):
				if not (models.Manifest().find_duplicate(y["vessel"],y["voyage"],y["port"])):
					man = models.Manifest()
					man.blob = filekey.key()
					man.vessel_name = y["vessel"]
					man.voyage = y["voyage"]
					man.port = y["port"]
					man.put()
 #    					search.Index(name='Manifest').put(CreateDocument(y["vessel"], y["voyage"], y["port"], man))
			            	if y["vessel"]:
            					search.Index(name='Manifest').put(CreateDocument(y["vessel"], y["voyage"], y["port"], str(man.key)))
					for c in range(5, y["numrows"]):
						SaveManifestDetail(man.key, y, c, man.vessel_name, man.voyage, man.port)
			else:
				y="y"



		params = {
	  		"y": y,
    			}
		return self.render_template("testman.html", **params)
Ejemplo n.º 3
0
def readingList(filekey):
	dictd = lambda: defaultdict(dictd)
	y = dictd()
	wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
	sh = wb.sheet_by_index(int(sheet_name))      
#find col were readings start
	for a in range(0, 10):
		y["DAT"] = sh.cell_value(row, a)
		try: 
			if "Dat/Sup" in y["DAT"]:
				start_col = a+1
		except:
			pass

        row = int(row) 
	cols = sh.ncols
	y["filename"] = blobstore.BlobInfo.get(filekey).filename
	y["product"] = sh.cell_value(10,1)

	end_col = 22

    	params = {
	    "y": y,

    	}
   	return params
Ejemplo n.º 4
0
	def get(self, keyval):
		resource = str(urllib.unquote(keyval))
    		blob_info = blobstore.BlobInfo.get(resource)

		wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(blob_info.key()).read())
                v = addVesselData(wb, blob_info.filename.replace(" ", ""))
		y = makeManifestPickle(wb)
		if (y["header"] == "manifest"):
			if not (models.Manifest().find_duplicate(y["vessel"],y["voyage"],y["port"])):
				man = models.Manifest()
				man.blob = blob_info.key()
				man.vessel_name = y["vessel"]
				man.voyage = y["voyage"]
				man.port = y["port"]
				man.put()
				for c in range(5, y["numrows"]):
					SaveManifestDetail(man.key, y, c, man.vessel_name, man.voyage, man.port)
			else:
				y="Manifest added already"
                         


		params = {
	 			"y": y,
    			}
		return self.render_template("testman.html", **params)
Ejemplo n.º 5
0
	def get(self, keyval):
		resource = str(urllib.unquote(keyval))
    		blob_info = blobstore.BlobInfo.get(resource)

		wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(blob_info.key()).read())
		sheet = wb.sheet_by_index(0)
		data = [sheet.cell_value(0, col) for col in range(sheet.ncols)]
		if not ("MOL REEFER MANIFEST" in data):
			iname = str(blob_info.filename.replace(" ", ""))
			delete_all_in_index(iname, "text")
			delete_all_in_index(iname, "date")
			delete_all_in_index(iname, "number")
                	y = addVesselData(wb, iname)
			s = matchManifest(iname)
			updateContainerStatus(iname)
			
		else:
			y = makeManifestPickle(wb)
			if not (models.Manifest().find_duplicate(y["vessel"],y["voyage"],y["port"])):
				man = models.Manifest()
				man.blob = blob_info.key()
				man.vessel_name = y["vessel"]
				man.voyage = y["voyage"]
				man.port = y["port"]
				man.put()
				for c in range(5, y["numrows"]):
					SaveManifestDetail(man.key, y, c, man.vessel_name, man.voyage, man.port)
			else:
				y="Manifest added already"

		params = {
	 			"y": y,
    			}
		return self.render_template("testman.html", **params)
Ejemplo n.º 6
0
  def get(self, filekey, sheet_name):
	dictd = lambda: defaultdict(dictd)
	y = dictd()
	wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
	sh = wb.sheet_by_index(int(sheet_name))
	row = 33
#find col were readings start
	for a in range(0, 10):
		y["DAT"] = sh.cell_value(row, a)
		try:
			if "Dat/Sup" in y["DAT"]:
				start_col = a+1
		except:
			pass
	y["start_col"] = start_col

	for a in range(25, 32):
		if "Number" in sh.cell_value(a,0):
			y["start"] = a + 3
  	for c in range(y["start"], sh.nrows , 2):
            y["container"][c] =  sh.cell_value(c,0)
	    y["container"]["ppecbcode"][c] = sh.cell_value(c,1)
    	    y["container"]["vent"][c] =  sh.cell_value(c,2)
	    y["container"]["setpoint"][c] = sh.cell_value(c,3)
            y["rows"] =  sh.nrows
            y["filekey"] =  filekey
            y["sheet_name"] =  sheet_name
       	    for g in range(5, 10):
		try:
	            foo = sh.cell_value(c, g)
		    amDAtemp, pmDAtemp = foo.split("/")
		    foo2 = sh.cell_value(c+1, g)
		    amRAtemp, pmRAtemp = foo2.split("/")
   		    AMdiff = Decimal(amDAtemp) - Decimal(amRAtemp)
		    PMdiff = Decimal(pmDAtemp) - Decimal(pmRAtemp)
	       	    y["AMDiff"][g] = AMdiff
	       	    y["PMDiff"][g] = PMdiff
       		    y["AMDiff"]["class"][g] = "default"
       		    y["PMDiff"]["class"][g] = "default"
 	            if (Decimal(AMdiff) >= Decimal(-0.2)):
		    	y["AMDiff"]["class"][c][g] = "darkgreen"
#			y["colour"][c] = "darkgreen"
	            if (Decimal(AMdiff) >= Decimal(-0.5)):
		    	y["AMDiff"]["class"][c][g] = "lightgreen"
#			y["colour"][c] = "lightgreen"
		    if (Decimal(AMdiff) <= Decimal(-1.0)):
		    	y["AMDiff"]["class"][c][g] = "lightred"
			y["colour"][c] = "lightred"
  	            if (Decimal(AMdiff) <= Decimal(-2.0)):
		    	y["AMDiff"]["class"][c][g] = "darkred"
			y["colour"][c] = "darkred"
		except:
			pass


    	params = {
	    "y": y,

    	}
   	return self.render_template('containerlist.html', **params)
Ejemplo n.º 7
0
    def get(self):
        get_data = blobstore.BlobInfo.all()
        fkey = get_data.fetch(get_data.count())
        for dat in range(0, get_data.count()):
            filekey = fkey[dat]
            wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
            y = makeVesselPickle(wb)

            params = {"y": y}
        return self.render_template("testman.html", **params)
Ejemplo n.º 8
0
    def get(self):
        get_data = blobstore.BlobInfo.all()
        fkey = get_data.fetch(get_data.count())
        for dat in range(0, get_data.count()):
            filekey = fkey[dat]
            wb = xlrd.open_workbook(file_contents=blobstore.BlobReader("gTVCfxI_4_-lNK1L1lmKKQ==").read())
            y = addVesselData(wb)

            params = {"y": y}
        return self.render_template("testman.html", **params)
Ejemplo n.º 9
0
	def get(self):
		get_data = blobstore.BlobInfo.all()
		fkey = get_data.fetch(get_data.count())
		for dat in range(0, get_data.count()):
			filekey = fkey[dat]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
			y = makeVesselPickle(wb)


			params = {
		  		"y": y,
	    			}
		return self.render_template("testman.html", **params)
Ejemplo n.º 10
0
    def get(self, filekey):
        wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
        # 	s = wb.sheet_by_index(0)
        y = makePickle(filekey)
        if y["manifest"] == "MOL REEFER MANIFEST":
            filename = "manifestlist.html"
        else:
            filename = "vessellist.html"

        params = {"y": y}

        # 	filename = "manifestlist.html"
        return self.render_template(filename, **params)
Ejemplo n.º 11
0
	def get(self):
		get_data = blobstore.BlobInfo.all()
		fkey = get_data.fetch(get_data.count())
		for dat in range(0, get_data.count()):
			filekey = fkey[dat]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader("gTVCfxI_4_-lNK1L1lmKKQ==").read())
			y = addVesselData(wb)


			params = {
		  		"y": y,
	    			}
		return self.render_template("testman.html", **params)
Ejemplo n.º 12
0
  def get(self):
#TODO set requests
      #  from_container = 0

        to_container = 3
	from_container = self.request.get('from_container')

    		#query = Suggestion.query().order(-Suggestion.when)
    	if from_container:
		from_container = self.request.get('from_container')
	else:
        	from_container = 0
#TODO select key from request get
	blob_key="-3cfYPZI8Rx1VLEkofj-DQ=="
	blob_reader = blobstore.BlobReader(blob_key)

	wb = xlrd.open_workbook(file_contents=blob_reader.read())
	#sh = wb.sheet_by_index(0)
#TODO add cape town durban etc
        sh = wb.sheet_by_name("FDEC")

        con_range = range(C_START, C_START+(to_container*2),2)

	dictd = lambda: defaultdict(dictd)
	y = dictd()
        for i in range(from_container,to_container):
		y["voyage"] =  sh.cell_value(9,1)
                y["date_of_loading"] =  (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(11,1), 0))[0:6])).strftime('%d-%m-%Y')
                y["product"] =  sh.cell_value(10,1)
                y["port"] = sh.cell_value(11,0)
                y["vesselname"] = sh.cell_value(8,1)
    		y["container"][i] =  sh.cell_value(con_range[i],0)
		y["container"]["ppecbcode"][i] = sh.cell_value(con_range[i],1)
    		y["container"]["vent"][i] =  sh.cell_value(con_range[i],2)
		y["container"]["setpoint"][i] = sh.cell_value(con_range[i],3)
		for j in range(0,4):
			y["container"]["DAtemp"][i][j] = sh.cell_value(con_range[i],5+j)
			y["container"]["RAtemp"][i][j] = sh.cell_value(con_range[i]+1,5+j)
          		y["container"]["date_"][i][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(29, 5 + j), 0))[0:6])).strftime('%d-%m-%Y')
			y["container"]["day"][i][j] = str(j+1)+" Day "


    	params = {
	    "y": y,
	    "from_container": from_container,
	    "to_container": to_container,

    	}


   	return self.render_template('shiplist.html', **params)
Ejemplo n.º 13
0
  def get(self, filekey):
	wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
#	s = wb.sheet_by_index(0)
	y = makePickle(filekey)
	if (y["manifest"] == 'MOL REEFER MANIFEST'):
		filename = "manifestlist.html"
	else:
		filename = "vessellist.html"

	params = {
	    "y": y,

    	}

#	filename = "manifestlist.html"
   	return self.render_template(filename, **params)
Ejemplo n.º 14
0
	def get(self):
		get_data = blobstore.BlobInfo.all()
		fkey = get_data.fetch(get_data.count())
		for dat in range(0, get_data.count()):
			filekey = fkey[dat]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
			y = makeVesselPickle(wb)
#			if not "manifest" in y:
#				pass
#			man = models.Vessel()
#			man.blob = filekey.key()
#				man.vessel = y["vessel"]
#				man.voyage = y["voyage"]
			#	man.port = y["port"]
#			man.put()
#				for c in range(5, y["numrows"]):
#					SaveManifestDetail(man.key, y, c)
    	
			params = {
		  		"y": y,
	    			}
		return self.render_template("testman.html", **params)
Ejemplo n.º 15
0
    def get(self, keyval):
        resource = str(urllib.unquote(keyval))
        blob_info = blobstore.BlobInfo.get(resource)

        wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(blob_info.key()).read())
        v = addVesselData(wb, blob_info.filename.replace(" ", ""))
        y = makeManifestPickle(wb)
        if y["header"] == "manifest":
            if not (models.Manifest().find_duplicate(y["vessel"], y["voyage"], y["port"])):
                man = models.Manifest()
                man.blob = blob_info.key()
                man.vessel_name = y["vessel"]
                man.voyage = y["voyage"]
                man.port = y["port"]
                man.put()
                for c in range(5, y["numrows"]):
                    SaveManifestDetail(man.key, y, c, man.vessel_name, man.voyage, man.port)
            else:
                y = "Manifest added already"

        params = {"y": y}
        return self.render_template("testman.html", **params)
Ejemplo n.º 16
0
	def get(self):
		get_data = blobstore.BlobInfo.all()
		fkey = get_data.fetch(get_data.count())
		for dat in range(0, get_data.count()):
			filekey = fkey[dat]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
			y = makeManifestPickle(wb)
			if (y["header"] == "manifest"):
				if not (models.Manifest().find_duplicate(y["vessel"],y["voyage"],y["port"])):
					man = models.Manifest()
					man.blob = filekey.key()
					man.vessel_name = y["vessel"]
					man.voyage = y["voyage"]
					man.port = y["port"]
					man.put()
					for c in range(5, y["numrows"]):
						SaveManifestDetail(man.key, y, c)
    	
		params = {
	  		"y": y,
    			}
		return self.render_template("testman.html", **params)    	
Ejemplo n.º 17
0
  def get(self, filekey, sheet_name, row):
	dictd = lambda: defaultdict(dictd)
	y = dictd()
	start_col =1
	wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
	sh = wb.sheet_by_index(int(sheet_name))
 	y["filekey"] = filekey
 	y["sheet_name"] = sheet_name
 	y["row"] = row
#whats happening with this -1?
        row = int(row)
	cols = sh.ncols
	y["filename"] = blobstore.BlobInfo.get(filekey).filename
	y["product"] = sh.cell_value(10,1)
#find col were readings start
	for a in range(0, 10):
		y["DAT"] = sh.cell_value(row, a)
		try:
			if "Dat/Sup" in y["DAT"]:
				start_col = a+1
		except:
			pass

#find col were readings end
	for a in range(start_col, 40):
		try:
			y["DAT"] = sh.cell_value(row, a)
#			if "Dat/Sup" in y["DAT"]:
#				pass
		except:
			end_col = 21

#find start date
	for c in range(start_col, 20):
		if "Dat/Sup" in y["DAT"]:
			start_col = a+1

	end_col = 22

	y["start_col"] = start_col
	y["end_col"] = end_col
	y["container"] =  sh.cell_value(row,0)
	for j in range(start_col, end_col):
		y["count"][j] = j - start_col + 1
		try:
			y["DAtemp"][j] = sh.cell_value(row, j)
			foo = sh.cell_value(row, j)
			y["DAtempAM"][j], y["DAtempPM"][j] = foo.split("/")

		except:
			y["DAtemp"][j] = "NA"

		try:
	       		y["RAtemp"][j] = sh.cell_value(row+1, j)
			foo = sh.cell_value(row+1, j)
			y["RAtempAM"][j], y["RAtempPM"][j] = foo.split("/")
		except:
	       		y["RAtemp"][j] = "NA"
		try:
			y["date_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime('%d-%m-%Y')
			y["day_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime('%d')
			y["month_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime('%m')
			y["year_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime('%Y')
		except:
		 	y["date_"][j] = "Date error"

#diffences
		try:
			foo = sh.cell_value(row, j)
			amDAtemp, pmDAtemp = foo.split("/")
			foo2 = sh.cell_value(row+1, j)
			amRAtemp, pmRAtemp = foo2.split("/")
                      #  amt = amDAtemp - amRAtemp
			AMdiff = Decimal(amDAtemp) - Decimal(amRAtemp)
			PMdiff = Decimal(pmDAtemp) - Decimal(pmRAtemp)
	       		y["AMDiff"][j] = AMdiff
	       		y["PMDiff"][j] = PMdiff
       			y["AMDiff"]["class"][j] = "default"
       			y["PMDiff"]["class"][j] = "default"
		        if (Decimal(AMdiff) <= Decimal(-1.0)):
		       			y["AMDiff"]["class"][j] = "lightred"

		        if (Decimal(AMdiff) >= Decimal(-0.5)):
		       			y["AMDiff"]["class"][j] = "lightgreen"

		        if (Decimal(AMdiff) >= Decimal(-0.2)):
		       			y["AMDiff"]["class"][j] = "darkgreen"

		        if (Decimal(AMdiff) <= Decimal(-2.0)):
		       			y["AMDiff"]["class"][j] = "darkred"


#			PMdiff

		        if (Decimal(PMdiff) <= Decimal(-1.0)):
		       			y["PMDiff"]["class"][j] = "lightred"

		        if (Decimal(PMdiff) >= Decimal(-0.5)):
		       			y["PMDiff"]["class"][j] = "lightgreen"

		        if (Decimal(PMdiff) >= Decimal(-0.2)):
		       			y["PMDiff"]["class"][j] = "darkgreen"

		        if (Decimal(PMdiff) <= Decimal(-2.0)):
		       			y["PMDiff"]["class"][j] = "darkred"

		except:
	       		y["AMDiff"][j] = "NA"



    	params = {
	    "y": y,

    	}
   	return self.render_template('readingslist.html', **params)
Ejemplo n.º 18
0
def getWorkbook(filekey):
    wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
    return wb
Ejemplo n.º 19
0
def makePickle(filekey):
	dictd = lambda: defaultdict(dictd)
	y = dictd()
	wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
	for i, x in enumerate(wb.sheets()):
    		header_cells = x.row(0)
    		sh = wb.sheet_by_index(i)
    		num_rows = x.nrows - 1
    		curr_row = 0
    		mid_row = 0
    		header = [each.value for each in header_cells]
    		if 'MOL REEFER MANIFEST' in header:
        		y["manifest"] = 'MOL REEFER MANIFEST'
	    		while curr_row < num_rows:
	        		curr_row += 1

	        		row = [int(each.value)
	               		if isinstance(each.value, float)
	               		else each.value
	               		for each in sh.row(curr_row)]

	        		value_dict = dict(zip(header, row))
	        		value_dict['title'] = x.name
	        		if 'Vessel:' in row:
	           			y["voyage"] = row[row.index('Voyage:')+1] 
	           			y["vessel"] = row[row.index('Vessel:')+1] 
	           			y["port"] = row[row.index('Port:')+1] 
	        		if 'BOOKING NO' in row:
	           			y["labels"] = row
	           			mid_row = curr_row+1
	
		        	y["acv"][curr_row] = row
				y["myfloat"][curr_row] = sh.cell_value(curr_row,5)
				y["numrows"] = num_rows+1


		else:

			y["key"] = blobstore.BlobInfo.get(filekey).key()
			y["sheetname"][i] = sh.name
			y["index"][i] = i
			y["nsheets"] = wb.nsheets
			for a in range(5, 15):
				if "VESSEL" in sh.cell_value(a,0):
	                                if (len(sh.cell_value(a,1)) > 0):
						y["vesselname"][i] = sh.cell_value(a,1)
					else:
						y["vesselname"][i] = "NA"

				if "VOYAGE" in sh.cell_value(a,0):
	                                if (len(sh.cell_value(a,1)) > 0):
						y["voyage"][i] = sh.cell_value(a,1)
						y["voyage_fixed"] = sh.cell_value(a,1)

					else:
						y["voyage"][i] = "NA"


				if "DATE of LOADING" in sh.cell_value(a,0):
					try:
						if (validate((datetime(*(xlrd.xldate_as_tuple(sh.cell_value(a, 1), 0))[0:6])).strftime('%d-%m-%Y'))):
							y["date_of_loading"][i] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(a, 1), 0))[0:6])).strftime('%d-%m-%Y')
					except:
						y["date_of_loading"][i] = "None"
			
	
        
			y["colour"] = "lightred"
                
			#y["bool"] = addDataFilename(y["vesselname"][i],	y["voyage_fixed"], "", i, y["date_of_loading"][i])


	return y
Ejemplo n.º 20
0
    def get(self, filekey, sheet_name, row):
        dictd = lambda: defaultdict(dictd)
        y = dictd()
        start_col = 1
        wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
        sh = wb.sheet_by_index(int(sheet_name))
        y["filekey"] = filekey
        y["sheet_name"] = sheet_name
        y["row"] = row
        # whats happening with this -1?
        row = int(row)
        cols = sh.ncols
        y["filename"] = blobstore.BlobInfo.get(filekey).filename
        y["product"] = sh.cell_value(10, 1)
        # find col were readings start
        for a in range(0, 10):
            y["DAT"] = sh.cell_value(row, a)
            try:
                if "Dat/Sup" in y["DAT"]:
                    start_col = a + 1
            except:
                pass

        # find col were readings end
        for a in range(start_col, 40):
            try:
                y["DAT"] = sh.cell_value(row, a)
            # 			if "Dat/Sup" in y["DAT"]:
            # 				pass
            except:
                end_col = 21

        # find start date
        for c in range(start_col, 20):
            if "Dat/Sup" in y["DAT"]:
                start_col = a + 1

        end_col = 22

        y["start_col"] = start_col
        y["end_col"] = end_col
        y["container"] = sh.cell_value(row, 0)
        for j in range(start_col, end_col):
            y["count"][j] = j - start_col + 1
            try:
                y["DAtemp"][j] = sh.cell_value(row, j)
                foo = sh.cell_value(row, j)
                y["DAtempAM"][j], y["DAtempPM"][j] = foo.split("/")

            except:
                y["DAtemp"][j] = "NA"

            try:
                y["RAtemp"][j] = sh.cell_value(row + 1, j)
                foo = sh.cell_value(row + 1, j)
                y["RAtempAM"][j], y["RAtempPM"][j] = foo.split("/")
            except:
                y["RAtemp"][j] = "NA"
            try:
                y["date_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime("%d-%m-%Y")
                y["day_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime("%d")
                y["month_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime("%m")
                y["year_"][j] = (datetime(*(xlrd.xldate_as_tuple(sh.cell_value(28, j), 0))[0:6])).strftime("%Y")
            except:
                y["date_"][j] = "Date error"

            # diffences
            try:
                foo = sh.cell_value(row, j)
                amDAtemp, pmDAtemp = foo.split("/")
                foo2 = sh.cell_value(row + 1, j)
                amRAtemp, pmRAtemp = foo2.split("/")
                #  amt = amDAtemp - amRAtemp
                AMdiff = Decimal(amDAtemp) - Decimal(amRAtemp)
                PMdiff = Decimal(pmDAtemp) - Decimal(pmRAtemp)
                y["AMDiff"][j] = AMdiff
                y["PMDiff"][j] = PMdiff
                y["AMDiff"]["class"][j] = "default"
                y["PMDiff"]["class"][j] = "default"
                if Decimal(AMdiff) <= Decimal(-1.0):
                    y["AMDiff"]["class"][j] = "lightred"

                if Decimal(AMdiff) >= Decimal(-0.5):
                    y["AMDiff"]["class"][j] = "lightgreen"

                if Decimal(AMdiff) >= Decimal(-0.2):
                    y["AMDiff"]["class"][j] = "darkgreen"

                if Decimal(AMdiff) <= Decimal(-2.0):
                    y["AMDiff"]["class"][j] = "darkred"

                # 			PMdiff

                if Decimal(PMdiff) <= Decimal(-1.0):
                    y["PMDiff"]["class"][j] = "lightred"

                if Decimal(PMdiff) >= Decimal(-0.5):
                    y["PMDiff"]["class"][j] = "lightgreen"

                if Decimal(PMdiff) >= Decimal(-0.2):
                    y["PMDiff"]["class"][j] = "darkgreen"

                if Decimal(PMdiff) <= Decimal(-2.0):
                    y["PMDiff"]["class"][j] = "darkred"

            except:
                y["AMDiff"][j] = "NA"

        params = {"y": y}
        return self.render_template("readingslist.html", **params)
Ejemplo n.º 21
0
def getWorkbook(filekey):
    wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(filekey).read())
    return wb
Ejemplo n.º 22
0
def updateContainerStatus(manifest_key):
	for index in search.get_indexes(fetch_schema=True, namespace="text"):
		query = models.ManifestDetail.query(models.ManifestDetail.manifest == manifest_key)
		detail = query.fetch(query.count())
		print "FINDME "+index.name
		try:
			findblob_from_index = models.LinktoManifest.query(models.LinktoManifest.filename_stripped == index.name).fetch(1)[0]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(findblob_from_index.blob).read())
		except:		
			findblob_from_index = models.LinktoManifest.query().fetch(1)[0]
			wb = xlrd.open_workbook(file_contents=blobstore.BlobReader(findblob_from_index.blob).read())

		for dat in detail:
#			print "FINDME2 "+blobstore.BlobInfo.get(dat.manifest.get().blob).filename
			ind = index_search(dat.container_number, index.name)
			if (ind):
				dat.container_status=True
				dat.sheet = ind[4]
				dat.put()
		#		print dat.key
		#		print dat.sheet				
				code = index_search("row=%i AND text=%s" % (ind[2], dat.code), index.name)
				if (code):
					dat.code_status=True
					dat.put()
				#vents = index_search("row=%i AND text=%s" % (ind[2], dat.vents), index.name)
				#find vents with in statement
				sh = wb.sheet_by_name(ind[4])

				row = sh.row(int(ind[2]))
				cell = sh.cell_value(int(ind[2]), (int(ind[3]))+2) 
				set_temp = sh.cell_value(int(ind[2]), (int(ind[3]))+3)


				num = map(int, re.findall(r'\d+', dat.vents))
				cell_num = map(int, re.findall(r'\d+', cell))

				temp_num = map(int, re.findall(r'\d+', dat.temp))
				set_num = map(int, re.findall(r'\d+', str(set_temp)))

				if (temp_num == set_num):
					dat.temp_status=True
					dat.put()
				elif (set_temp == dat.temp):
					dat.temp_status=True
					dat.put()


#				print "mapped: "+str(num)
#				print "cell: "+str(cell)
#				print "strin1"+string1

				if (num == cell_num):
					dat.vents_status=True
					dat.put()
				elif (cell == dat.vents):
					dat.vents_status=True
					dat.put()					

				temp = index_search("row=%i AND text=%s" % (ind[2], dat.temp), index.name)
				if (temp):
					dat.temp_status=True
					dat.put()



	return ind