Esempio n. 1
0
def get_jdg_history():
    hostname= os.getenv('JDG_HOSTNAME','0.0.0.0')
    basepath=os.getenv('BASE_PATH','/opt/imagerecognize/')
    remote_cache = RemoteCache(host=hostname)
    #os.chdir(basepath)

    files=glob.glob(".rad-img-recog/*")
    mock_data={}
    mock_data["results"]=[]
    bulk_data= remote_cache.bulk_get()
    for f in files:
        name=bulk_data[(f.split("/")[1])]
        data =json.loads(name)
        #print data
        mock_data["results"].append({
            "filename": f.split("/")[1],
            "classification": data["pred"][0][1],
            "percentage":data["pred"][0][0]
        })
    mock_data['time_taken']=remote_cache.get("time_taken")
    mock_data['last_transaction']=remote_cache.get("last_transaction")

    if (len(files) <10):
        mock_data["num_results"]=len(files)
        mock_data["num_pages"]=1
    else:
        mock_data["num_results"]=len(files)
        total_files=len(files)
        num= total_files/10
        if( total_files %10 != 0):
            num= num+1
        mock_data["num_pages"]= num
    print (mock_data)
    return Response(json.dumps(mock_data), status=200, mimetype="application/json")
Esempio n. 2
0
 def __init__(self, config):
   super(HotRodCacheClient, self).__init__(config["host"], config["port"], config["cache"])
   self.config = config
   if config["hotrod.use_river_string_keys"] in TRUE_STR_VALUES:
     self.river_keys = RiverStringCodec()
   else:
     self.river_keys = None
   if self.cache_name == DEFAULT_CACHE_NAME: 
     self.cache_name = "";
   self.remote_cache = RemoteCache(self.host, int(self.port), self.cache_name)
   return
Esempio n. 3
0
def img_recognize():
    start = timer()

    if not os.path.exists(app.config['UPLOAD_FOLDER']):
        os.makedirs(app.config['UPLOAD_FOLDER'])

    file = request.files['file']

    # TODO :
    #if file and allowed_file(file.filename):

    filename = secure_filename(file.filename)
    img_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
    file.save(img_path)

    # Use Inception Model
    inception.data_dir = app.config['INCEPTION_MODEL']
    inception.maybe_download()
    model = inception.Inception()
    pred = model.classify(image_path=img_path)
    scores = model.get_scores(pred=pred, k=5)
    model.close()

    #Getting environment variable or using default localhost
    hostname=os.getenv('JDG_HOSTNAME','0.0.0.0')

    remote_cache = RemoteCache(host=hostname)
    times = datetime.datetime.now().strftime("%B-%d-%Y-%I:%M%p")
    key= filename
    remote_cache.put("last_transaction", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    remote_cache.put(key, json.dumps({'pred':scores, 'timestamp': times , 'filename': filename}) )
    print remote_cache.stats()
    print "Key: %s" % key
    # Send data
    resp = {'pred': scores}

    end = timer()
    total=end - start


    remote_cache.put( "time_taken" , str(total) )

    return Response(
        json.dumps(resp),
        status=200, mimetype="application/json")
Esempio n. 4
0
 def __init__(self, config):
   super(HotRodCacheClient, self).__init__(config["host"], config["port"], config["cache"])
   self.config = config
   if config["hotrod.use_river_string_keys"] in TRUE_STR_VALUES:
     self.river_keys = RiverStringCodec()
   else:
     self.river_keys = None
   if self.cache_name == DEFAULT_CACHE_NAME: 
     self.cache_name = "";
   self.remote_cache = RemoteCache(self.host, int(self.port), self.cache_name)
   return
Esempio n. 5
0
class HotRodCacheClient(CacheClient):
  """HotRod cache client implementation."""
    
  def __init__(self, config):
    super(HotRodCacheClient, self).__init__(config["host"], config["port"], config["cache"])
    self.config = config
    if config["hotrod.use_river_string_keys"] in TRUE_STR_VALUES:
      self.river_keys = RiverStringCodec()
    else:
      self.river_keys = None
    if self.cache_name == DEFAULT_CACHE_NAME: 
      self.cache_name = "";
    self.remote_cache = RemoteCache(self.host, int(self.port), self.cache_name)
    return

  def _optionally_encode_key(self, key_unmarshalled):
      if self.river_keys == None:
        return key_unmarshalled;
      else:
        return self.river_keys.encode(key_unmarshalled)

  def put(self, key, value, version=None, lifespan=None, max_idle=None, put_if_absent=False):
    key = self._optionally_encode_key(key)
    if lifespan == None:
      lifespan=0 
    if max_idle == None:
      max_idle=0
    try:
      if (version == None):
        if (put_if_absent):
          retval = self.remote_cache.put_if_absent(key, value, lifespan, max_idle)
          if retval:
            return
          else:
            raise ConflictError
        else:
          self.remote_cache.put(key, value, lifespan, max_idle)
      else:
          numversion = None
          try:
            numversion = int(version)
          except ValueError:
            self._error("hotrod client only accepts numeric versions")
          retval = self.remote_cache.replace_with_version(key, value, numversion, lifespan, max_idle)
          if retval == 1:
            return
          elif retval == 0:
            raise NotFoundError
          elif retval == -1:
            raise ConflictError
          else:
            self._error("unexpected return value from hotrod client")
    except RemoteCacheError as e:
      self._error(e.args)
        
  def get(self, key, get_version=False):
    try:
      value = None
      version = None
      key = self._optionally_encode_key(key)
      if get_version:
        version, value = self.remote_cache.get_versioned(key)
      else:
        value = self.remote_cache.get(key)
      if value == None:
        raise NotFoundError
      if get_version:
        return version, value
      else:
        return value
    except RemoteCacheError as e:
      self._error(e.args)

  def delete(self, key, version=None):
    try:
      key = self._optionally_encode_key(key)
      if version == None:
        retval = self.remote_cache.remove(key)
        if retval:
          return
        else:
          raise NotFoundError
      else:
        numversion = None
        try:
          numversion = int(version)
        except ValueError:
          self._error("hotrod client only accepts numeric versions")
        retval = self.remote_cache.remove_with_version(key, numversion)
        if retval == 1:
          return
        elif retval == 0:
          raise NotFoundError
        elif retval == -1:
          raise ConflictError
        else:
          self._error("unexpected return value from hotrod client")
      
    except RemoteCacheError as e:
      self._error(e.args)
    
  def clear(self):
    self.remote_cache.clear()
    
  def exists(self, key):
    try:
      key = self._optionally_encode_key(key)
      if not self.remote_cache.contains_key(key):
        raise NotFoundError
    except RemoteCacheError as e:
      self._error(e.args) 
Esempio n. 6
0
class HotRodCacheClient(CacheClient):
  """HotRod cache client implementation."""
    
  def __init__(self, config):
    super(HotRodCacheClient, self).__init__(config["host"], config["port"], config["cache"])
    self.config = config
    if config["hotrod.use_river_string_keys"] in TRUE_STR_VALUES:
      self.river_keys = RiverStringCodec()
    else:
      self.river_keys = None
    if self.cache_name == DEFAULT_CACHE_NAME: 
      self.cache_name = "";
    self.remote_cache = RemoteCache(self.host, int(self.port), self.cache_name)
    return

  def _optionally_encode_key(self, key_unmarshalled):
      if self.river_keys == None:
        return key_unmarshalled;
      else:
        return self.river_keys.encode(key_unmarshalled)

  def put(self, key, value, version=None, lifespan=None, max_idle=None, put_if_absent=False):
    key = self._optionally_encode_key(key)
    if lifespan == None:
      lifespan=0 
    if max_idle == None:
      max_idle=0
    try:
      if (version == None):
        if (put_if_absent):
          retval = self.remote_cache.put_if_absent(key, value, lifespan, max_idle)
          if retval:
            return
          else:
            raise ConflictError
        else:
          self.remote_cache.put(key, value, lifespan, max_idle)
      else:
          numversion = None
          try:
            numversion = int(version)
          except ValueError:
            self._error("hotrod client only accepts numeric versions")
          retval = self.remote_cache.replace_with_version(key, value, numversion, lifespan, max_idle)
          if retval == 1:
            return
          elif retval == 0:
            raise NotFoundError
          elif retval == -1:
            raise ConflictError
          else:
            self._error("unexpected return value from hotrod client")
    except RemoteCacheError as e:
      self._error(e.args)
        
  def get(self, key, get_version=False):
    try:
      value = None
      version = None
      key = self._optionally_encode_key(key)
      if get_version:
        version, value = self.remote_cache.get_versioned(key)
      else:
        value = self.remote_cache.get(key)
      if value == None:
        raise NotFoundError
      if get_version:
        return version, value
      else:
        return value
    except RemoteCacheError as e:
      self._error(e.args)

  def delete(self, key, version=None):
    try:
      key = self._optionally_encode_key(key)
      if version == None:
        retval = self.remote_cache.remove(key)
        if retval:
          return
        else:
          raise NotFoundError
      else:
        numversion = None
        try:
          numversion = int(version)
        except ValueError:
          self._error("hotrod client only accepts numeric versions")
        retval = self.remote_cache.remove_with_version(key, numversion)
        if retval == 1:
          return
        elif retval == 0:
          raise NotFoundError
        elif retval == -1:
          raise ConflictError
        else:
          self._error("unexpected return value from hotrod client")
      
    except RemoteCacheError as e:
      self._error(e.args)
    
  def clear(self):
    self.remote_cache.clear()
    
  def exists(self, key):
    try:
      key = self._optionally_encode_key(key)
      if not self.remote_cache.contains_key(key):
        raise NotFoundError
    except RemoteCacheError as e:
      self._error(e.args) 
Esempio n. 7
0
def main():
    remote_cache = RemoteCache()
    for i in range(0, NUM_ENTRIES):
        value = random.randint(0, MAX_VAL)
        remote_cache.put(str(i), str(value))
def main():
	remote_cache = RemoteCache()
	for i in range(0, NUM_ENTRIES):
		value = random.randint(0, MAX_VAL)
		remote_cache.put(str(i),str(value))
Esempio n. 9
0
import sys
from infinispan.remotecache import RemoteCache

hostname = 'datagrid-hotrod'
port = 11333
itemID = 'SalesItem13'

remote_cache = RemoteCache(host=hostname, port=port)

def addRecord(itemID):
    [miss, val] = remote_cache.put_if_absent(itemID, '1', ret_prev=True)

    if miss == False:
        remote_cache.put(itemID, str(int(val)+1))

addRecord(itemID)
salesItem = remote_cache.get(itemID)
print('Sales of item: ' + salesItem)