original_docstring:  Create a complete data set merging informations from:
          last catalog, prices, refill and stock files available
          and save it to db as json string
  
          Returns record id.
          clean   @bool : whether keep the fs cleaned or not;
          
docstring: Create a complete data set merging informations from:
  last catalog, prices, refill and stock files available
  and save it to db as json string
  
  Returns record id.
  clean   @bool : whether keep the fs cleaned or not.
docstring_tokens: Create a complete data set merging informations from : last catalog prices refill and stock files available and save it to db as json string Returns record id . clean @bool : whether keep the fs cleaned or not .
code: def build_updates(cls, clean=True):
          """ Create a complete data set merging informations from:
          last catalog, prices, refill and stock files available
          and save it to db as json string
  
          Returns record id.
          clean   @bool : whether keep the fs cleaned or not;
          """
  
          # 1. Extract last updated data from db
          repos = ("arch_cat", "arch_avl", "arch_pri", "arch_apt",)
  
          res = db(db.archive.archname.belongs(repos)).select()
          assert len(res)==len(repos), "Error!"
  
          actuals = res.group_by_value(db.archive.archname)
  #         _actuals = db(db.archive.archname.belongs(repos))._select(db.archive.id)
  
          apaths = {an: cls.retrieve(rows[0]) for an,rows in actuals.iteritems()}
  
          # UID code columns for each archive type.
          UID = {
             "arch_cat": "Codice",
             "arch_pri": "Codice Articolo",
             "arch_avl": "Product SKU",
             "arch_apt": "Codice Articolo"
          }
  
          fields = {
              "arch_cat": None, # That means ALL columns!
              "arch_pri": ("Larghezza", "Profondità", "Altezza", "Peso",),
              "arch_apt": ("Prezzo Netto", "Inizio Promozione", "Fine Promozione",),
              "arch_avl": ("Stock Quantity",)
          }
  
          # Value adjustments
          adjustments = {
              # Weight adjustment (From gr to kg)
              "Peso": lambda v: v and ("%.3f" % (float(v)/1000)).replace(".", ","),
              "Prezzo Netto": lambda v: v and ("%.2f" % float(v)).replace(".", ",")
          }
  
          # Rows by uuid for each archive
          acnts = {}
          aflds = {}
          for an, nfo in apaths.iteritems():
              with open(nfo["tab0"]) as source:
                  ardr = csv.DictReader(source)
                  acnts[an] = {row[UID[an]]: row for row in ardr}
                  if fields[an] is None:
                      aflds[an] = ardr.fieldnames
                  else:
                      aflds[an] = fields[an]
  
          fieldnames = tuple(sum([list(aflds[k]) for k in repos], []))
          _buildRow = lambda puk,k: acnts["arch_avl"][puk].get(k, acnts["arch_pri"][puk].get(k, acnts["arch_cat"][puk].get(k, acnts["arch_apt"][puk].get(k))))
  
          data = {}
          for puk in sorted(set.intersection(*map(set, acnts.values()))):
              arow = {k: _buildRow(puk, k) for k in fieldnames}
              for k,f in adjustments.iteritems():
                  arow[k] = f(arow[k])
              data[puk] = arow
  
          try:
              out = db.product_catalog.insert(
                  pdata = data,
                  fieldnames = fieldnames,
                  checksums = sorted(set((r.checksum for r in res)))
              )
          except IntegrityError:
              db.rollback()
              return 0
          else:
              db.commit()
      
              if clean:
                  for paths in [apaths,]:
                      for __an, nfo in paths.iteritems():
                          for __, filepath in nfo.iteritems():
                              keep_fs_clean(filepath)
  
          return out
code_tokens: def build_updates ( cls , clean = True ) : repos = ( "arch_cat" , "arch_avl" , "arch_pri" , "arch_apt" , ) res = db ( db . archive . archname . belongs ( repos ) ) . select ( ) assert len ( res ) == len ( repos ) , "Error!" actuals = res . group_by_value ( db . archive . archname ) apaths = { an : cls . retrieve ( rows [ 0 ] ) for an , rows in actuals . iteritems ( ) } UID = { "arch_cat" : "Codice" , "arch_pri" : "Codice Articolo" , "arch_avl" : "Product SKU" , "arch_apt" : "Codice Articolo" } fields = { "arch_cat" : None , "arch_pri" : ( "Larghezza" , "Profondità",   Altezza",   Peso", ) ,  "arch_apt" : ( "Prezzo Netto" , "Inizio Promozione" , "Fine Promozione" , ) , "arch_avl" : ( "Stock Quantity" , ) } adjustments = { "Peso" : lambda v : v and ( "%.3f" % ( float ( v ) / 1000 ) ) . replace ( "." , "," ) , "Prezzo Netto" : lambda v : v and ( "%.2f" % float ( v ) ) . replace ( "." , "," ) } acnts = { } aflds = { } for an , nfo in apaths . iteritems ( ) : with open ( nfo [ "tab0" ] ) as source : ardr = csv . DictReader ( source ) acnts [ an ] = { row [ UID [ an ] ] : row for row in ardr } if fields [ an ] is None : aflds [ an ] = ardr . fieldnames else : aflds [ an ] = fields [ an ] fieldnames = tuple ( sum ( [ list ( aflds [ k ] ) for k in repos ] , [ ] ) ) _buildRow = lambda puk , k : acnts [ "arch_avl" ] [ puk ] . get ( k , acnts [ "arch_pri" ] [ puk ] . get ( k , acnts [ "arch_cat" ] [ puk ] . get ( k , acnts [ "arch_apt" ] [ puk ] . get ( k ) ) ) ) data = { } for puk in sorted ( set . intersection ( * map ( set , acnts . values ( ) ) ) ) : arow = { k : _buildRow ( puk , k ) for k in fieldnames } for k , f in adjustments . iteritems ( ) : arow [ k ] = f ( arow [ k ] ) data [ puk ] = arow try : out = db . product_catalog . insert ( pdata = data , fieldnames = fieldnames , checksums = sorted ( set ( ( r . checksum for r in res ) ) ) ) except IntegrityError : db . rollback ( ) return 0 else : db . commit ( ) if clean : for paths in [ apaths , ] : for __an , nfo in paths . iteritems ( ) : for __ , filepath in nfo . iteritems ( ) : keep_fs_clean ( filepath ) return out
short_docstring: Create a complete data set merging informations from:
  last catalog, prices, refill and stock files available
  and save it to db as json string
short_docstring_tokens: Create a complete data set merging informations from : last catalog prices refill and stock files available and save it to db as json string
comment: """ Create a complete data set merging informations from:
          last catalog, prices, refill and stock files available
          and save it to db as json string
  
          Returns record id.
          clean   @bool : whether keep the fs cleaned or not;
          """$SEP$# 1. Extract last updated data from db$SEP$#         _actuals = db(db.archive.archname.belongs(repos))._select(db.archive.id)$SEP$# UID code columns for each archive type.$SEP$# That means ALL columns!$SEP$# Value adjustments$SEP$# Weight adjustment (From gr to kg)$SEP$# Rows by uuid for each archive