def __init__(self, state, x_next, depth, x_depth, directed, neighbour): super(DistanceControl, self).__init__(directed) self.__x_next = x_next self.__depth = depth self.__x_depth = x_depth self.__neighbour = neighbour self.__max_weight = state.session.query(max_(Graph.weight)).one()[0]
def __init__(self, state, x_next, depth, x_depth, directed, neighbour): super(WeightedControl, self).__init__(directed) self.__x_next = x_next self.__depth = depth self.__x_depth = x_depth self.__neighbour = neighbour self.__max_weight = state.session.query(max_(Graph.weight)).one()[0]
def add_calculation(self, proposal_id, calculator_id, mode, version, input_, output, calc_version, title): with self._transaction() as conn: calculation_alias = calculation.alias() result = conn.execute(calculation.insert().values({ calculation.c.proposal_id: proposal_id, calculation.c.sort_order: select([ coalesce(max_(calculation_alias.c.sort_order), 0) + 1 ]).where(calculation_alias.c.proposal_id == proposal_id), calculation.c.calculator_id: calculator_id, calculation.c.mode: mode, calculation.c.version: version, calculation.c.input: input_, calculation.c.output: output, calculation.c.date_run: datetime.utcnow(), calculation.c.calc_version: calc_version, calculation.c.title: title, })) return result.inserted_primary_key[0]
def collect(session, zero): max_weight = session.query(max_(Graph.weight)).one()[0] zero *= max_weight LOG.info('Collecting all nodes, edges with weights over {0:7.1f} (max {1:7.1f}).'.format(zero, max_weight)) edges = set(session.query(Graph).filter(Graph.weight > zero).all()) nodes = set(edge.from_ for edge in edges) nodes.update(edge.to_ for edge in edges) LOG.info('Collected {0}/{1} nodes and {2}/{3} edges.'.format( len(nodes), session.query(LastFmArtist).count(), len(edges), session.query(Graph).count())) return (nodes, edges, zero)
def collect(session, zero): max_weight = session.query(max_(Graph.weight)).one()[0] zero *= max_weight LOG.info( 'Collecting all nodes, edges with weights over {0:7.1f} (max {1:7.1f}).' .format(zero, max_weight)) edges = set(session.query(Graph).filter(Graph.weight > zero).all()) nodes = set(edge.from_ for edge in edges) nodes.update(edge.to_ for edge in edges) LOG.info('Collected {0}/{1} nodes and {2}/{3} edges.'.format( len(nodes), session.query(LastFmArtist).count(), len(edges), session.query(Graph).count())) return (nodes, edges, zero)
def add_calculation(self, proposal_id, calculator_id, mode, version, input_, output, calc_version, title): with self._transaction() as conn: calculation_alias = calculation.alias() result = conn.execute(calculation.insert().values({ calculation.c.proposal_id: proposal_id, calculation.c.sort_order: select( [coalesce(max_(calculation_alias.c.sort_order), 0) + 1] ).where(calculation_alias.c.proposal_id == proposal_id), calculation.c.calculator_id: calculator_id, calculation.c.mode: mode, calculation.c.version: version, calculation.c.input: input_, calculation.c.output: output, calculation.c.date_run: datetime.utcnow(), calculation.c.calc_version: calc_version, calculation.c.title: title, })) return result.inserted_primary_key[0]