<commit_before>from totalimpact.models import Item
import totalimpact.dao as dao
import time
from totalimpact.tilogging import logging
log = logging.getLogger(__name__)

# some data useful for testing
# d = {"DOI" : ["10.1371/journal.pcbi.1000361", "10.1016/j.meegid.2011.02.004"], "URL" : ["http://cottagelabs.com"]}

class Queue(dao.Dao):
    __type__ = None
        
    def __init__(self):
        # inherit the init
        super(Queue,self).__init__()

    # TODO: 
    # return next item from this queue (e.g. whatever is on the top of the list
    # does NOT remove item from tip of queue
    def first(self):
        if len(self.queue) > 0:
            return self.queue[0]
        else:
            return None
        #return Item(**{'_rev': '4-a3e3574c44c95b86bb2247fe49e171c8', '_id': 'test', '_deleted_conflicts': ['3-2b27cebd890ff56e616f3d7dadc69c74'], 'hello': 'world', 'aliases': {'URL': ['http://cottagelabs.com'], 'DOI': ['10.1371/journal.pcbi.1000361', "10.1016/j.meegid.2011.02.004"]}})
    
    # implement this in inheriting classes if needs to be different
    def save_and_unqueue(self,item):
        # alter to use aliases method once exists
        item.data[self.__type__]['last_modified'] = time.time()
        item.save()
        log.info("Saved and unqueued item " + item.id)
        
        
class AliasQueue(Queue):
    __type__ = 'aliases'
    
    @property
    def queue(self):
        addr = 'queues/' + self.__type__
        items = self.view(addr)
        # due to error in couchdb this reads from json output - see dao view
        return [Item(**i['value']) for i in items['rows']]
        #return [Item(**i['value']) for i in items.rows]
    
class MetricsQueue(Queue):
    __type__ = 'metrics'
    
    def __init__(self,prov=None):
        # inherit the init
        super(MetricsQueue,self).__init__()
        self._provider = prov
    
    @property
    def provider(self):
        try:
            return self._provider
        except:
            self._provider = None
            return self._provider
        
    @provider.setter
    def provider(self, _provider):
        self._provider = _provider

    @property
    def queue(self):
        # change this for live
        addr = 'queues/' + self.__type__
        if self.provider:
            items = self.view(addr, startkey=[self.provider,0,0], endkey=[self.provider,9999999999,9999999999])
        else:
            items = self.view(addr)
        # due to error in couchdb this reads from json output - see dao view
        return [Item(**i['value']) for i in items['rows']]
        #return [Item(**i['value']) for i in items.rows]
<commit_msg>updating queue addr to viewname<commit_after>from totalimpact.models import Item
import totalimpact.dao as dao
import time
from totalimpact.tilogging import logging
log = logging.getLogger(__name__)

# some data useful for testing
# d = {"DOI" : ["10.1371/journal.pcbi.1000361", "10.1016/j.meegid.2011.02.004"], "URL" : ["http://cottagelabs.com"]}

class Queue(dao.Dao):
    __type__ = None
        
    def __init__(self):
        # inherit the init
        super(Queue,self).__init__()

    # TODO: 
    # return next item from this queue (e.g. whatever is on the top of the list
    # does NOT remove item from tip of queue
    def first(self):
        if len(self.queue) > 0:
            return self.queue[0]
        else:
            return None
        #return Item(**{'_rev': '4-a3e3574c44c95b86bb2247fe49e171c8', '_id': 'test', '_deleted_conflicts': ['3-2b27cebd890ff56e616f3d7dadc69c74'], 'hello': 'world', 'aliases': {'URL': ['http://cottagelabs.com'], 'DOI': ['10.1371/journal.pcbi.1000361', "10.1016/j.meegid.2011.02.004"]}})
    
    # implement this in inheriting classes if needs to be different
    def save_and_unqueue(self,item):
        # alter to use aliases method once exists
        item.data[self.__type__]['last_modified'] = time.time()
        item.save()
        log.info("Saved and unqueued item " + item.id)
        
        
class AliasQueue(Queue):
    __type__ = 'aliases'
    
    @property
    def queue(self):
        viewname = 'queues/' + self.__type__
        items = self.view(viewname)
        # due to error in couchdb this reads from json output - see dao view
        return [Item(**i['value']) for i in items['rows']]
        #return [Item(**i['value']) for i in items.rows]
    
class MetricsQueue(Queue):
    __type__ = 'metrics'
    
    def __init__(self,prov=None):
        # inherit the init
        super(MetricsQueue,self).__init__()
        self._provider = prov
    
    @property
    def provider(self):
        try:
            return self._provider
        except:
            self._provider = None
            return self._provider
        
    @provider.setter
    def provider(self, _provider):
        self._provider = _provider

    @property
    def queue(self):
        # change this for live
        viewname = 'queues/' + self.__type__
        if self.provider:
            items = self.view(viewname, startkey=[self.provider,0,0], endkey=[self.provider,9999999999,9999999999])
        else:
            items = self.view(viewname)
        # due to error in couchdb this reads from json output - see dao view
        return [Item(**i['value']) for i in items['rows']]
        #return [Item(**i['value']) for i in items.rows]

{'fraction_non_alphanumeric': 0.12387724550898203, 'fraction_numerical': 0.04491017964071856, 'mean_word_length': 2.482084690553746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3473944', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1661, 'n_words': 450}