Exemplo n.º 1
0
def CG7():
	t1 = table.Table("data/posthistory.xml")
	t2 = group(t1,["PostId","UserId"])
	t3 = select(t1,attributes=["PostId","UserId"])
	t3 = join(t2,t2,[("UserId","UserId")])
	t4 = group(t3,["PostId1","PostId2"])
	g = graph.Graph("undirected",False)
	g.addNodes(t1,"PostId")
	g.addEdges(t4,"PostId1","PostId2")
	return g
Exemplo n.º 2
0
def CG8():
	t1 = table.Table("data/posthistory.xml")
	t2 = group(t1,["UserId"],["PostId","CreationDate"],"list")
	t3 = order(t2,"PostId","CreationDate") # In each row, order postIds by date
	t4 = expand(t3) # Generate table with one row for each consecutive pair of postIds in each row of the original table
	g = graph.Graph("directed",False)
	g.addNodes(t1,"PostId")
	g.addEdges(t4,"PostId1","PostId2")
	return g
Exemplo n.º 3
0
def CG1():
	t1 = table.Table("data/posts.xml")
	t2 = select(t1, Condition("PostTypeId","==", 1), ["Id","OwnerUserId"])
	t3 = select(t1, Condition("PostTypeId","==", 2), ["ParentId","OwnerUserId"])
	t4 = join(t2,t3,[("Id","ParentId")])
	t5 = group(t4, ["OwnerUserId1", "OwnerUserId2"], "Count", "cnt")
	g = graph.Graph("directed")
	g.addNodes(t1,"OwnerUserId")
	g.addEdges(t5,"OwnerUserId1","OwnerUserId2",["Count"])
	return g
Exemplo n.º 4
0
def CG2():
	t1 = table.Table("data/posts.xml") #["Id","PostTypeId","OwnerUserId",...] 
	t2 = table.Table("data/votes.xml") #["PostId","VoteTypeId","UserId",...]
	t3 = select(t1, attributes=["Id","OwnerUserId"])
	t4 = select(t2, Condition("VoteTypeId", "==", 2),["PostId","UserId"])
	t5 = join(t4,t3,[("PostId","Id")])
	t6 = group(t5,["UserId","OwnerUserId"], "Count","cnt")
	g = graph.Graph("directed")
	g.addNodes(t1,"OwnerUserId")
	g.addNodes(t2,"UserId")
	g.addEdges(t6,"UserId","OwnerUserId",["Count"])
	return g
Exemplo n.º 5
0
def CG9():
	t1 = table.Table("data/badges.xml") #[UserId","Name"...]
	t2 = table.Table("data/posts.xml") #["Id","PostTypeId","OwnerUserId",...]
	t3 = join(t1,t2,["UserId"],["OwnerUserId"],["Name"],["PostTypeId","ParentId","Id"])
	t4 = select(t3, Condition("PostTypeId", "==", 1)) #Questions
	t5 = select(t3, Condition("PostTypeId", "==", 2)) #Answers
	t6 = join(t5,t4,["ParentId"],["Id"],["Name"],["Name"],["Id","Badge1","Badge2"])
	t7 = group(t6,["Badge1","Badge2"],"Count","cnt")
	g = graph.Graph("directed")
	g.addNodes(t1,"Name")
	g.addEdges(t7,"Badge1","Badge2",["Count"])
	return g
Exemplo n.º 6
0
    def attr(self, name):
        if name == 'url':
            r = self.doc.request
            query = dict(hl = self.hl, disc = r('disc'), adpr = r('adpr'), cdef = r('cdef'))
            if isfiche(self.source):
                return self.doc.geturl(self.param[:1] + self.param[2:], 
                                       query = query, view = self.view, addmod = False)
            else:
                return self.doc.geturl(self.param[:const.PRODUCT_URL_LEN] + [self.partno1], 
                                       query = query, addview = False, addmod = False)
        elif name == 'image':
            return self.doc.getimage(self.id_image, self, self.param)

        elif name == 'imagebig':
            if isproduct(self.source) and self.images:
                return self.images[0]

        elif name == 'images':
            q = sql.get_fval(['id_image'], 'image_deps', 'id_obj')
            q = sql.order(q, 'id')
            res = []
            i = 1
            for id in self.db.fetchvals(q, [self.id]):
                img = self.doc.getimage(id, self, self.param, i)
                res.append(img)
                i += 1
            return res

        elif name == 'stored':                	
            qstore = sql.get_fval('SUM(quantity)', 'store', 'id_product')
            return self.db.fetchval(qstore, [self.id])

        elif name == 'store':
            fields = ['SUM(s.quantity) AS quantity', 'pr.val1 AS eta', 'peta.name AS etaname']
            f = ['p.id = s.id_store', 'id_product = %s']
            f.append('pr.id_prop = p.id')
            f.append('pr.name = "ETA"')
            f.append('peta.translit = pr.val1')
            qstore = sql.get_f(fields, ['store s', 'prop p', 'param pr', 'prop peta'], f)
            qstore = sql.group(qstore, 'eta')
            qstore = sql.order(qstore, 'eta')
            res = Storage()
            res.data = self.db.fetchobj(qstore, [self.id])
            res.quantity = self.stored
            res.available = True if self.stored else False
            q = sql.get_f('p.*', ['param pr', 'prop p'], ['pr.id_prop = %s', 'pr.name = "ETA"', 'p.translit = pr.val1'])
            res.default = self.db.fetchrowobj(q, [self.view.id_cat])
            return res

        return None
Exemplo n.º 7
0
    def prodlist(self, doc, qsort):
        q = doc.sqlpids(doc.view.pview, self.ppair)
        pid = db.fetchvals(q)
        if not pid:
            self.NotFound('Fiche not found')
        pid = pid[0]

        k = doc.kseries
        modellist = map(lambda k: k.name, (k[1], k[3], k[2]))
        translist = map(lambda k: k.translit, doc.kseries)

        fiche = db.fetchobject(doc.tproduct, pid)
        fiche.model = '%s %s %s' % tuple(modellist)
        fiche.img   = doc.geturl(translist, ext = 'gif')
        fiche.imgs  = doc.geturl(translist, img ='preview', ext = 'gif')
        img_addcrc(db, fiche.img, fiche.id_image)
        img_addcrc(db, fiche.imgs, fiche.id_image)
        self.add(fiche = fiche)

        q = sql.get_fval(['*'], doc.tprice, 'id_product')
        if qsort[0][0] == 'name':
            qsort[0] = ('CAST(num AS UNSIGNED)', 'ASC')

        q = sql.group(q, 'num, name')
        q = sql.order(q, qsort)
        prices = db.fetchobj(q, [pid])
        log.t_trace('DOCatFiche.Prepare.Price requested')
        for row in prices:
            row.price = float(row.price) * float(site.config("CURRENCY", 2))
            row.price = doc.getprice(row.price, True, row.currency)
            row.code  = formatnumber(row.id, 9)
            row.req = row.req or ''
        log.t_trace('DOCatFiche.Price formatted')

        self.add(show_all = True)
        self.ppg = site.config('PROD_PER_PAGE', 2)
        self.prodcount = len(prices)

        i = self.ppg * (self.page - 1)
        prices = prices[i:i + self.ppg]

        log.t_trace('DOCatFiche.Prepare.Before return')
        return prices
Exemplo n.º 8
0
# CG1
import table
import graph
from gbuild import makeGraph
from sql import select, project, rename, join, group
from condition import Condition

t1 = table.Table("data/posts.xml")
t2 = select(t1, Condition("PostTypeId", "==", 1), ["Id", "OwnerUserId"])
t3 = select(t1, Condition("PostTypeId", "==", 2), ["ParentId", "OwnerUserId"])
t4 = join(t2, t3, [("Id", "ParentId")])
t5 = group(t4, ["OwnerUserId1", "OwnerUserId2"], "Count", "cnt")
g = graph.Graph("directed")
g.addNodes(t1, "OwnerUserId", [])
g.addEdges(t5, "UserId1", "UserId2", ["Count"])

# CG2
import table
import graph
from gbuild import makeGraph
from sql import select, project, rename, join, group
from condition import Condition

t1 = table.Table("data/posts.xml")  #["Id","PostTypeId","OwnerUserId",...]
t2 = table.Table("data/votes.xml")  #["PostId","VoteTypeId","UserId",...]
t3 = select(t2, Condition("VoteTypeId", "==", 2))
t4 = join(t3, t1, ["PostId"], ["Id"], ["UserId"], ["OwnerUserId"],
          ["Id", "UserId1", "UserId2"])
t5 = group(t4, ["UserId1", "UserId2"], "Count", "cnt")
g = graph.Graph("directed")
g.addNodes(t1, "OwnerUserId", [])
Exemplo n.º 9
0
    def __proddata(self, db, view, pids):
        doc = self.doc
        view = doc.view0
        fields = ['p.id', 'p.partno1']
        tables = [doc.tpropset]

        k = len(view.groups) + 1
        for i in xrange(1, k):
            tables.append('LEFT JOIN prop p%d ON ps.id_prop%d = p%d.id' % (i, i, i))
            fields.append('MAX(p%d.translit) AS t%d' % (i, i))

        tables = ["\n  ".join(tables)]

        fields += ['p.name, p.note, p.price, p.price_in, p.price_out, p.currency, p.eta']
        fields += ['img.id AS id_img']
        tables.append(doc.tproduct + ' LEFT JOIN ' + doc.timage + ' ON p.id_image = img.id')
        fq = sql.get_f(['ids.id_image'], 'image_deps ids', 'ids.id_obj = p.id')
        fq = sql.order(fq, 'ids.id')
        fq = sql.limit(fq, 0, 1)
        fq = '(%s) AS id_img_big' % fq
        fields.append(fq)

        fstore = sql.get_f('SUM(s.quantity)', 'store s', ['s.id_product = p.id', 's.quantity > 0'])
        fstore = '(%s) AS stored' % fstore
        fields += [fstore]

        f = [sql.fin('p.id', pids)]
        f.append("p.id = ps.id_product")
        f.append("ps.pview = '%s'" % view.pview)
        q = sql.get_f(fields, tables, f)
        q = sql.group(q, 'p.id')
        pl = {}
        iml = []
        for (key, row) in db.fetchdic(q).iteritems():
            param = []
            for prop in xrange(1, k):
                param.append(row['t' + str(prop)])
            row.param = param
            row.smallprice = doc('list_view') == "store"

            p = classes.Product(doc, row)
            p.hints = []
            p.rates = []
            p.view  = view
            pl[key] = p

            iml.append(p.id_img)
            iml.append(p.id_img_big)

        iml = notemptylist(iml)
        if iml:
            f = sql.fin('id', iml)
            q = sql.get_f(['id', 'name', 'type', 'width', 'height', 'size'], 'image', f)
            images = db.fetchdic(q)
        else:
            images = {}
        crclist = []

        for p in pl.itervalues():
            p.img = doc.getimage(images.get(p.id_img, None), p, p.param, crclist = crclist)
            p.img_big = doc.getimage(images.get(p.id_img_big, None), p, p.param, 1, crclist = crclist)

        img_addcrclist(db, crclist)

        return pl
Exemplo n.º 10
0
    def getfblocks(self, doc):
        # Creating filter blocks
        blocks = doc.view.blocks
        Q_IDPRP = 'ps.id_prop%d'

        fblocks = []
        i = 0
        for b in blocks:
            log.t_trace("Cat Filter.beforeblock")
            if b.show:

                t = doc.tpropset
                f = map(lambda x: (Q_IDPRP + ' = %d') % x, b.filter.iteritems())
                f.append("ps.pview = '%s'" % doc.view.pview)
                f.append(Q_IDPRP % b.propno + ' IS NOT NULL')
                f += doc.view.adfilter.sql(True)

                q = sql.get_f([Q_IDPRP % b.propno], t, f)
                f = ['ps.pview'] + map(lambda x: Q_IDPRP % x, b._group + [b.propno])
                q = sql.group(q, f)
                idl = db.fetchvals(q)
                proplist = []
                if idl:
                    f = ["id IN (%s)" % (", ".join(map(str, idl)))]
                    q = sql.get_f(['name', 'fname', 'translit', 'id_image'], 'prop', f)
                    q = sql.order(q, 'name')
                    proplist = db.fetchobj(q)

                b.hidden = b.hidden or not len(proplist)

                block = Storage()
                block.group = b.group
                block.active = False
                bd = []
                block.data = bd

                url = doc.geturl(b.params)

                bd.append(Storage(dict(url = url, name = LEX_ALL, st = 'ACT')))
                log.t_trace("Cat Filter.beforequery")
                avgwidth = 0
                for prop in proplist:
                    params = b.params[:]
                    params[i] = prop.translit

                    prop.url = doc.geturl(params)

                    if b.k and b.k.translit == prop.translit:
                        prop.st = 'ACT'
                        bd[0]['st'] = 'GEN'
                        block.active = True
                    else:
                        prop.st = 'GEN'

                    width = min(len(prop.name), 30) * 6

                    prop.image = doc.getimage(prop.id_image, prop, [prop.translit])
                    #if prop.image:
                    #    width = prop.image.width
                    avgwidth += width
                    bd.append(prop)

                if avgwidth:
                    avgwidth /= len(proplist)                

                log.t_trace("Cat Filter.afterequery")

                block.columns = self.getcolumns(avgwidth, len(bd), b)
                block.b = b                
                fblocks.append(block)
            i += 1 
            log.t_trace("Cat Filter.afterblock")
        return fblocks
Exemplo n.º 11
0
# CG1
import table
import graph
from gbuild import makeGraph
from sql import select, project, rename, join, group
from condition import Condition
t1 = table.Table("data/posts.xml")
t2 = select(t1, Condition("PostTypeId","==", 1), ["Id","OwnerUserId"])
t3 = select(t1, Condition("PostTypeId","==", 2), ["ParentId","OwnerUserId"])
t4 = join(t2,t3,[("Id","ParentId")])
t5 = group(t4, ["OwnerUserId1", "OwnerUserId2"], "Count", "cnt")
g = graph.Graph("directed")
g.addNodes(t1,"OwnerUserId",[])
g.addEdges(t5,"UserId1","UserId2",["Count"])

# CG2
import table
import graph
from gbuild import makeGraph
from sql import select, project, rename, join, group
from condition import Condition
t1 = table.Table("data/posts.xml") #["Id","PostTypeId","OwnerUserId",...] 
t2 = table.Table("data/votes.xml") #["PostId","VoteTypeId","UserId",...]  
t3 = select(t2, Condition("VoteTypeId", "==", 2))
t4 = join(t3,t1,["PostId"],["Id"],["UserId"],["OwnerUserId"],["Id","UserId1","UserId2"])
t5 = group(t4,["UserId1","UserId2"], "Count","cnt")
g = graph.Graph("directed")
g.addNodes(t1,"OwnerUserId",[])
g.addNodes(t2,"UserId",[])
g.addEdges(t5,"UserId1","UserId2",["Count"])