def set(id_, class_, description, environment, author, lat=None, lng=None, files=None): """ write environment description to the database class_ : environment class id_ : unified identifier of environment environment : owl description author: author of the description """ transport = roboearth.openDBTransport() client = transport['client'] mutation_list =list() #create paths path = class_.replace(' ', '').lower().strip('.') + '.' +id_.replace(' ', '').lower().strip('.') wwwPath = roboearth.DOMAIN + os.path.join("data/", 'elements/', path.replace('.', '/')) path = os.path.join(roboearth.UPLOAD_DIR, 'elements/', path.replace('.', '/')) if class_.lower() == "osm": try: # try geocoding lat, lng = GeoData.geocoding(query=id_, service="osm") mutation_list.append(Mutation(column="info:lat", value=lat)) mutation_list.append(Mutation(column="info:lng", value=lng)) envName = class_.replace(' ', '').lower().strip('.') + '.' + lat.replace(".", ",") + '.'+lng.replace(".", ",") except Exception, err: raise roboearth.FormInvalidException("For class \"osm\" the identifier has to consist of two float (<lat>;<lng>) or of an description of a location (e.g. address): " + err.__str__())
def set(id_, class_, description, environment, author, lat=None, lng=None, files=None): """ write environment description to the database class_ : environment class id_ : unified identifier of environment environment : owl description author: author of the description """ transport = roboearth.openDBTransport() client = transport['client'] mutation_list = list() #create paths path = class_.replace(' ', '').lower().strip('.') + '.' + id_.replace( ' ', '').lower().strip('.') wwwPath = roboearth.DOMAIN + os.path.join("data/", 'elements/', path.replace('.', '/')) path = os.path.join(roboearth.UPLOAD_DIR, 'elements/', path.replace('.', '/')) if class_.lower() == "osm": try: # try geocoding lat, lng = GeoData.geocoding(query=id_, service="osm") mutation_list.append(Mutation(column="info:lat", value=lat)) mutation_list.append(Mutation(column="info:lng", value=lng)) envName = class_.replace( ' ', '').lower().strip('.') + '.' + lat.replace( ".", ",") + '.' + lng.replace(".", ",") except Exception, err: raise roboearth.FormInvalidException( "For class \"osm\" the identifier has to consist of two float (<lat>;<lng>) or of an description of a location (e.g. address): " + err.__str__())
def addEnv(row): """ add results to the output dictionary """ rating = row.columns['info:rating'].value output = { "id": row.row, "description": row.columns['info:description'].value, "author": row.columns['info:author'].value, "rating": rating, "environments": list(), "files": {} } #check subscription if user != "" and format == "html": scannerSub = client.scannerOpenWithPrefix( "Subscriptions", user + "#Environments#" + row.row, []) subRes = client.scannerGet(scannerSub) if subRes and subRes[0].row == user + "#Environments#" + row.row: output['subscribed'] = True else: output['subscribed'] = False if row.columns.has_key('info:modified_by'): output['modified_by'] = row.columns['info:modified_by'].value for r in row.columns: if r.startswith("file:"): url_ = res[0].columns[r].value file_ = roboearth.UPLOAD_DIR + url_[len(roboearth.BINARY_ROOT ):] output["files"][r[5:]] = { 'url': url_, 'mime-type': m.from_file(file_) } if row.columns.has_key("info:lat"): lat = row.columns['info:lat'].value lng = row.columns['info:lng'].value delta = 0.002607 output["location"] = {"latitude": lat, "longitude": lng} if format == "html": output['location']["html"] = GeoData.getEmbeddedMap( float(lat), float(lng), delta) else: output['location']['osm'] = { 'info': GeoData.reverseGeocoding(float(lat), float(lng), delta), 'raw_map_data': GeoData.getRawData(float(lat), float(lng), delta) } versions = client.getVer("Elements", row.row, "owl:description", numOfVersions) if format == "html": for v in versions: try: output['environments'].append({ 'timestamp': time.ctime(int(v.timestamp) / 1000), 'environment': xml.dom.minidom.parseString( v.value).toprettyxml(indent=" ") }) except: output['environments'].append({ 'timestamp': time.ctime(int(v.timestamp) / 1000), 'environment': v.value }) output['fullStars'] = range(int(rating)) output['emptyStars'] = range(10 - int(rating)) else: for v in versions: output['environments'].append({ 'timestamp': v.timestamp, 'environment': v.value.replace("\n", "") }) #if not roboearth.local_installation: # roboearth.send_twitter_message("download", "Environment", row.row) return output
def addEnv(row): """ add results to the output dictionary """ rating = row.columns['info:rating'].value output = {"id" : row.row, "description" : row.columns['info:description'].value, "author" : row.columns['info:author'].value, "rating" : rating, "environments" : list(), "files" : {}} #check subscription if user != "" and format=="html": scannerSub = client.scannerOpenWithPrefix("Subscriptions", user+"#Environments#"+row.row, [ ]) subRes = client.scannerGet(scannerSub) if subRes and subRes[0].row == user+"#Environments#"+row.row: output['subscribed'] = True else: output['subscribed'] = False if row.columns.has_key('info:modified_by'): output['modified_by'] = row.columns['info:modified_by'].value for r in row.columns: if r.startswith("file:"): url_ = res[0].columns[r].value file_ = roboearth.UPLOAD_DIR+url_[len(roboearth.BINARY_ROOT):] output["files"][r[5:]] = {'url' : url_, 'mime-type' : m.from_file(file_)} if row.columns.has_key("info:lat"): lat = row.columns['info:lat'].value lng = row.columns['info:lng'].value delta = 0.002607 output["location"] = {"latitude" : lat, "longitude" : lng} if format=="html": output['location']["html"] = GeoData.getEmbeddedMap(float(lat), float(lng), delta) else: output['location']['osm'] = {'info' : GeoData.reverseGeocoding(float(lat), float(lng), delta), 'raw_map_data' : GeoData.getRawData(float(lat), float(lng), delta)} versions = client.getVer("Elements", row.row, "owl:description", numOfVersions) if format=="html": for v in versions: try: output['environments'].append({ 'timestamp' : time.ctime(int(v.timestamp)/1000), 'environment' : xml.dom.minidom.parseString(v.value).toprettyxml(indent=" ") }) except: output['environments'].append({ 'timestamp' : time.ctime(int(v.timestamp)/1000), 'environment' : v.value}) output['fullStars'] = range(int(rating)) output['emptyStars'] = range(10 - int(rating)) else: for v in versions: output['environments'].append({ 'timestamp' : v.timestamp, 'environment' : v.value.replace("\n","")}) #if not roboearth.local_installation: # roboearth.send_twitter_message("download", "Environment", row.row) return output