def sql(self, query, N):
        def safeTerm(x):
            r = str(x)
            # make terms safe for ASP
            m = rGroundTerm.match(r)
            if m:
                #print("passthrough ground term {} / {}".format(repr(r), repr(m)))
                return r
            else:
                r = '"{}"'.format(x)
                #print("quoted {}".format(repr(r)))
                return r

        assert (isinstance(N, int))
        assert (isinstance(query, str))
        cur = self.connection().cursor()
        cur.execute(query)
        for t in cur:
            #logging.warning("got t from cursor: "+repr(t))
            if N != len(t):
                logging.warning("&sql{}[{}] got tuple of size {}".format(
                    N, query, len(t)))
            adaptedt = [safeTerm(x) for x in list(t)[:N]]
            while len(adaptedt) < N:
                adaptedt.append('null')
            acthex.output(tuple(adaptedt))
def persistenceByPred(pred):
    #logging.debug('persistenceByPred:'+repr(pred))
    assert (isinstance(pred, acthex.ID))
    assert (isinstance(acthex.environment(), PersistenceEnvironment))
    predstr = pred.value()
    for a in acthex.environment().atoms:
        logging.debug("in environment: " + repr(a))
        if a[0] == predstr:
            # output tuple with single term containing full atom
            term = '{}({})'.format(a[0], ','.join(a[1:]))
            logging.debug('persistenceByPred output:' + repr(term))
            acthex.output((term, ))
def geomInside(point, poly):
    #spoint, spoly = geomParsePointNocache(point), geomParsePolyNocache(poly)
    spoint, spoly = geomParsePoint(point), geomParsePoly(poly)
    #print("checking if {} is within {}".format(repr(spoint), repr(spoly)))
    if spoint.within(spoly):
        acthex.output(())
def timeStamp(t):

    #x = datetime.datetime.now()
    x = time.time()
    acthex.output(("\"" + str(x) + "\"", ))
def wsConnected(url):
    if acthex.environment().ws_connection is not None and acthex.environment(
    ).ws_connection.sock.connected:
        acthex.output(())
def wsReceive():

    # TODO: collect messages
    acthex.output(())
コード例 #7
0
def sortVal():
  assert(isinstance(acthex.environment(), PersistenceEnvironment))
  for idx, val in enumerate(acthex.environment().sequence):
    acthex.output( (idx, val) )