<commit_before>import urlparse
import os, sys, tempfile, json, re
import glob,time
#tools_dir = os.environ.get('TOOLSDIR')
#lib_path = os.path.abspath(tools_dir)
#sys.path.append(lib_path)
from msc_apps import *
from decimal import *

#data_dir_root = os.environ.get('DATADIR')

def offers_response(response_dict):
    expected_fields=['type','currencyType']
    for field in expected_fields:
        if not response_dict.has_key(field):
            return (None, 'No field '+field+' in response dict '+str(response_dict))
        if len(response_dict[field]) != 1:
            return (None, 'Multiple values for field '+field)
    
    if response_dict['type'][0].upper() == "TIME":
        time = int(response_dict['time'][0]) if 'time' in response_dict else 86400
        data = filterOffersByTime( response_dict['currencyType'][0] , time  )
    else:
        address_arr = json.loads(response_dict['address'][0])
        data = filterOffers(address_arr) if type( address_arr ) == type( [] ) else { 'ERR': 'Address field must be a list or array type' } 
    
    response_status='OK'
    response='{"status":"'+response_status+'", "data":'+ str(json.dumps(data)) +'}'
    
    return (response, None)

def filterOffersByTime( currency_type , time_seconds):
    #filter by currency
    currency = ('1' if (currency_type == 'OMNI' or currency_type == 'MSC') else '2')

    atleast_now = int( str( int(time.time() - time_seconds) ) + '000' )

    ROWS=dbSelect("select ao.*,t.txhash,t.protocol,t.txdbserialnum,t.txtype,t.txversion,t.ecosystem,t.txrecvtime,t.txstate,t.txerrorcode,"
                  "t.txblocknumber,t.txseqinblock,txj.txdbserialnum,txj.protocol,txj.txdata "
                  "from activeoffers ao, transactions t, txjson txj where ao.propertyidselling=%s and ao.propertyiddesired='0' and "
                  "ao.createtxdbserialnum=t.txdbserialnum and ao.createtxdbserialnum=txj.txdbserialnum", [currency])

    response = [ mapSchema(row) for row in ROWS if int(mapSchema(row)['tx_time']) > atleast_now ]

    return sorted(response, key=lambda x:  int(x['tx_time']) )
    
def mapSchema(row):
  #print row, 'row'
  try:
    rawdata = json.loads(row[-1])
  except TypeError:
    rawdata = row[-1]

  #We only map tx21 and tx22
  if row[-11] == 20:
    #print row
    ppc = Decimal( rawdata['bitcoindesired'] ) / Decimal( rawdata['amount'] )
    color = getcolor(row[10]) 
    response = {
      'action': -1, #don't have this data
      'block': str(row[-5]),<commit_msg>fix name / symbol change in offers filters<commit_after>import urlparse
import os, sys, tempfile, json, re
import glob,time
#tools_dir = os.environ.get('TOOLSDIR')
#lib_path = os.path.abspath(tools_dir)
#sys.path.append(lib_path)
from msc_apps import *
from decimal import *

#data_dir_root = os.environ.get('DATADIR')

def offers_response(response_dict):
    expected_fields=['type','currencyType']
    for field in expected_fields:
        if not response_dict.has_key(field):
            return (None, 'No field '+field+' in response dict '+str(response_dict))
        if len(response_dict[field]) != 1:
            return (None, 'Multiple values for field '+field)
    
    if response_dict['type'][0].upper() == "TIME":
        time = int(response_dict['time'][0]) if 'time' in response_dict else 86400
        data = filterOffersByTime( response_dict['currencyType'][0] , time  )
    else:
        address_arr = json.loads(response_dict['address'][0])
        data = filterOffers(address_arr) if type( address_arr ) == type( [] ) else { 'ERR': 'Address field must be a list or array type' } 
    
    response_status='OK'
    response='{"status":"'+response_status+'", "data":'+ str(json.dumps(data)) +'}'
    
    return (response, None)

def filterOffersByTime( currency_type , time_seconds):
    #filter by currency
    currency = ('1' if (currency_type in ['OMNI','OMN','MSC'] ) else '2')

    atleast_now = int( str( int(time.time() - time_seconds) ) + '000' )

    ROWS=dbSelect("select ao.*,t.txhash,t.protocol,t.txdbserialnum,t.txtype,t.txversion,t.ecosystem,t.txrecvtime,t.txstate,t.txerrorcode,"
                  "t.txblocknumber,t.txseqinblock,txj.txdbserialnum,txj.protocol,txj.txdata "
                  "from activeoffers ao, transactions t, txjson txj where ao.propertyidselling=%s and ao.propertyiddesired='0' and "
                  "ao.createtxdbserialnum=t.txdbserialnum and ao.createtxdbserialnum=txj.txdbserialnum", [currency])

    response = [ mapSchema(row) for row in ROWS if int(mapSchema(row)['tx_time']) > atleast_now ]

    return sorted(response, key=lambda x:  int(x['tx_time']) )
    
def mapSchema(row):
  #print row, 'row'
  try:
    rawdata = json.loads(row[-1])
  except TypeError:
    rawdata = row[-1]

  #We only map tx21 and tx22
  if row[-11] == 20:
    #print row
    ppc = Decimal( rawdata['bitcoindesired'] ) / Decimal( rawdata['amount'] )
    color = getcolor(row[10]) 
    response = {
      'action': -1, #don't have this data
      'block': str(row[-5]),
{'fraction_non_alphanumeric': 0.1446, 'fraction_numerical': 0.012, 'mean_word_length': 3.6738317757009344, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '5470747', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1696, 'n_words': 381}