Updates rating in the database
@param {Object} rating  The rating to add.
@param {Object} config  The optional config.
@param {Object} conn    The optional db connection.
@return {Object} Promise with success or fail.
545980
function rateLastSeen(params, config, conn) {

  // validate
  if ( params.rating === null || params.rating === undefined ) {
    return 'You must enter a valid rating'
  }

  var reviewer = params.reviewer || 1

  // defaults
  config = config || require('../config/config.js')


  // main
  return new Promise((resolve, reject) => {

    if (!conn) {
      var conn = wc_db.getConnection(config.db)
    }
    var datePublished
    var row

    getLastSeen(params, config.con).then(function(res) {
      row = res.ret[0][0]
      debug(row)
      datePublished = row.datePublished
      if (datePublished) {
        var sql = 'UPDATE Media set rating = :rating where id = :id'
      } else {
        var sql = 'UPDATE Fragment set rating = :rating where id = :id and start = :start'
      }
      debug('rateLastSeen', sql, params)

      return conn.query(sql, { replacements: { "rating" : params.rating, "id" : row.id, "start" : row.start } })

    }). then(function(ret) {
      if (datePublished) {
        var rating = {}
        rating.uri = row.uri
        rating.reviewer = reviewer
        rating.rating = params.rating
        debug('rateLastSeen', rating)
        return updateRating(rating, config, conn)
      } else {
        return 'done'
      }
    }).then(function(ret) {
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
1030566
def add_content_ratings(self, app_id, submission_id, security_code):
        
        url = self.url('content_ratings') % app_id
        return self.conn.fetch('POST', url,
                               {'submission_id': '%s' % submission_id,
                                'security_code': '%s' % security_code
                                })
758637
function Rating(props) {
  const { className, dataAttrs, rate, size } = props;

  const restProps = getDataAttributes(dataAttrs);

  const stars = Array.from(Array(size).keys());
  const value = Math.ceil((rate / size) * 100);

  return (
    <div className={classnames('ui-rating', className)} {...restProps}>
      {stars.map(v => <b key={v}>★</b>)}
      <div className="ui-rating-value" style={{ width: `${value}%` }}>
        {stars.map(v => <b key={v}>★</b>)}
      </div>
    </div>
  );
}
23125
function addUserSSLConfig(config) {
  if (config.https === true) {
    try {
      config.https = {
        cert: readFileSync(getSSLPath(config.host, SERVER_CERT_FILENAME)),
        key: readFileSync(getSSLPath(config.host, SERVER_KEY_FILENAME))
      };
    } catch (e) {}
  }

  return config;
}
149531
function(config) {
	  
     var client = mqtt.connect(config.server + ':' + config.port);
     client.subscribe(this.id);
     
	 client.on('message', function(topic, message) {
       /*
        * This is called when a result to a third party call request is delivered.  
        */
       l('DEBUG') && console.log('3PCC.mqttClient - Received Message on topic: '+topic);

	   //	First convert to a JS object;
       message = JSON.parse(message);
	   
		//	Next cancel the response timer.
		var respTimer = respTimerMap[message.transID];
		
		if (respTimer != null)
		{
		   clearInterval(respTimer);
		   delete respTimerMap[message.transID];
		}
		else
		{
			l('DEBUG') && console.log('3PCC.mqttClient - Received Message but could not find associated response timer');
		}
		
        try {
        	this.callback(message);
        } catch(e) {
          console.error('MqttClient Message callback chain failure:',e);
          console.log(e.stack);
        }
      }.bind(this));
	  
    client.on('connect', function(error) {
      //console.log('mqtt is CONNECTED');
      this.connected = true;
	  // Subscribe on unique ID to get the response back.
	  mqttClient.subscribe(this.id);
      this.emit('connected');
    }.bind(this));
    
	client.on('error', function(error) {
      console.log('DISCONNECTED - error: '+ error);
      this.connected = false;
      this.emit('disconnected', error);
    }.bind(this));
    
	client.on('close', function(error) {
      console.log('DISCONNECTED - close: '+error);
      this.connected = false;
      this.emit('disconnected',error);
    }.bind(this));
    return client;
  }
452406
def update(postid, userid, rating):
        '''
        
        '''
        rating_recs = TabRating.select().where(
            (TabRating.post_id == postid) & (TabRating.user_id == userid)
        )
        if rating_recs.count() > 0:
            MRating.__update_rating(rating_recs.get().uid, rating)
        else:
            MRating.__insert_data(postid, userid, rating)
672639
function(config) {
  
    //console.log('RtcConnector: createMqttClient: server:  '+ config.server);

     var client = mqtt.connect(config.server + ':' + config.port);
     client.on('message', function(topic, message) {
       /*
        * This is called when a topic matching a valid subsription is received
        *   We have a valid subscription somewhere... 
        *   TODO:  This must call the filter FOR the topic and ensure it hasn't already
        *   been called.  
        */
       l('MESSAGE') && console.log('RtcConnector.mqttClient - Received Message on topic: '+topic);
        try {
          doFilter(topic,message);
        } catch(e) {
          console.error('MqttClient Message callback chain failure:',e);
          console.log(e.stack);
        }
      });
    client.on('connect', function(error) {
      console.log('RtcConnector: mqtt is CONNECTED');
      this.connected = true;
      this.emit('connected');
    }.bind(this));
    client.on('error', function(error) {
      console.log('RtcConnector: DISCONNECTED - error:'+ error);
      this.connected = false;
      this.emit('disconnected', error);
    }.bind(this));
    client.on('close', function(error) {
      console.log('RtcConnector: DISCONNECTED - close: '+error);
      this.connected = false;
      this.emit('disconnected',error);
    }.bind(this));
    return client;
  }
414088
function updateLevel(cb){
			conn.query("SELECT MAX(level) AS max_level FROM units WHERE unit IN(?)", [objUnit.parent_units], function(rows){
				if (rows.length !== 1)
					throw Error("not a single max level?");
				conn.query("UPDATE units SET level=? WHERE unit=?", [rows[0].max_level + 1, objUnit.unit], function(){
					cb();
				});
			});
		}
471032
public function addToRatingAverage($rating)
    {
        $dOldRating = $this->oxarticles__oxrating->value;
        $dOldCnt = $this->oxarticles__oxratingcnt->value;
        $this->oxarticles__oxrating->setValue(($dOldRating * $dOldCnt + $rating) / ($dOldCnt + 1));
        $this->oxarticles__oxratingcnt->setValue($dOldCnt + 1);
        $dRating = ($dOldRating * $dOldCnt + $rating) / ($dOldCnt + 1);
        $dRatingCnt = (int) ($dOldCnt + 1);
        // oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $oDb->execute('update oxarticles set oxarticles.oxrating = ' . $dRating . ',oxarticles.oxratingcnt = ' . $dRatingCnt . ', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = ' . $oDb->quote($this->getId()));
    }
369816
function addReview(reviews, review) {
  if (!reviews.length) {
    return [review];
  }

  var i = reviews.length - 1;
  for (; i >= 0; i -= 1) {
    if (reviews[i].ts <= review.ts) {
      break;
    }
  }

  var newReviews = reviews.slice(0);
  newReviews.splice(i + 1, 0, review);

  return newReviews;
}
1034544
function Pool(config) {
	if(!(this instanceof Pool)) {
		return new Pool(config);
	}
	var self = this;
	if(!config) { throw new TypeError("config not set"); }
	self._pool = require('mysql').createPool(config);
	self._get_connection = Q.nfbind(self._pool.getConnection.bind(self._pool));
	db.Pool.call(this);
}
1314131
function updateLastSeen (params, config) {
  qpm_media.updateLastSeen(params, config).then(function (ret) {
    if (ret.conn) {
      var conn = ret.conn
      conn.close()
    }
  }).catch(function (err) {
    if (err.conn) {
      var conn = err.conn
      conn.close()
    }
    console.error(err.err)
  })
}
644807
protected function UpdateMainScroeValue()
    {
        $bRet = false;
        $sQuery = " SELECT AVG( `score` ) AS main_score FROM `pkg_shop_rating_service_rating` WHERE `pkg_shop_rating_service_id` = '".$this->id."' ";
        $rs = MySqlLegacySupport::getInstance()->query($sQuery);
        if ($rs) {
            $oAVG = MySqlLegacySupport::getInstance()->fetch_object($rs);
        }

        //Update value
        if ($oAVG->main_score > 0) {
            $sQuery = "UPDATE pkg_shop_rating_service SET current_rating = '".$oAVG->main_score."', current_rating_date = NOW() WHERE id = '".$this->id."' ";
            MySqlLegacySupport::getInstance()->query($sQuery);
            $bRet = $oAVG->main_score;
        }

        return $bRet;
    }
205466
public function onConnect(Connection $conn)
    {
        // 加入新连接重新调整所有连接rdy状态
        $conn->setDelegate($this);
        $conn->writeCmd(Command::subscribe($this->topic, $this->channel));
        $this->maybeUpdateRDY($conn);
    }
213249
int update(Config config, Connection conn, String sql, Object... paras) throws SQLException {
		PreparedStatement pst = conn.prepareStatement(sql);
		config.dialect.fillStatement(pst, paras);
		int result = pst.executeUpdate();
		DbKit.close(pst);
		return result;
	}
1185577
async function (showPrompts) {
    logger.step('** Deploying Value Registrar Contract');
    if (showPrompts) {
      // confirming the important addresses
      logger.info("Deployer Address: " + deployerAddress);
      logger.info("Value Ops Address: " + valueOpsAddress);

      await new Promise(
        function (onResolve, onReject) {
          prompts.question("Please verify all above details. Do you want to proceed? [Y/N]", function (intent) {
            if ((intent === 'Y') || (intent === 'y')) {
              logger.info('Great! Proceeding deployment.');
              prompts.close();
              onResolve();
            } else {
              logger.error('Exiting deployment scripts. Change the env vars and re-run.');
              process.exit(1);
            }
          });
        }
      );
    } else {
      prompts.close();
    }

    const contractDeployTxReceipt = await deployHelper.perform(valueRegistrarContractName, web3Provider,
      valueRegistrarContractAbi, valueRegistrarContractBin, valueDeployerName, {gasPrice: VC_GAS_PRICE, gas: VC_GAS_LIMIT});

    const valueRegistrarContractAddr = contractDeployTxReceipt.contractAddress;

    logger.step('** Setting Ops Address of Value Registrar contract to valueOps address and verifying it');
    const valueRegistrar = new ValueRegistrarKlass(valueRegistrarContractAddr);
    await valueRegistrar.setOpsAddress(valueDeployerName, valueOpsAddress);

    const getOpsAddressResponse = await valueRegistrar.getOpsAddress();

    if (!valueOpsAddress.equalsIgnoreCase(getOpsAddressResponse.data.address)) {
      logger.error('Exiting the deployment as opsAddress which was set just before does not match.');
      process.exit(1);
    }

    return Promise.resolve(responseHelper.successWithData(
      {contract: 'valueRegistrar', address: valueRegistrarContractAddr}));
  }
1227373
public static function connect(ConnectionConfig $connectionConfig, CancellationToken $token = null): Promise
    {
        $connectionString = \str_replace(";", " ", $connectionConfig->getConnectionString());

        try {
            $connection = new pq\Connection($connectionString, pq\Connection::ASYNC);
        } catch (pq\Exception $exception) {
            return new Failure(new ConnectionException("Could not connect to PostgreSQL server", 0, $exception));
        }

        $connection->nonblocking = true;
        $connection->unbuffered = true;

        $deferred = new Deferred;

        $callback = function () use ($connection, $deferred) {
            switch ($connection->poll()) {
                case pq\Connection::POLLING_READING:
                    return; // Connection not ready, poll again.

                case pq\Connection::POLLING_WRITING:
                    return; // Still writing...

                case pq\Connection::POLLING_FAILED:
                    $deferred->fail(new ConnectionException($connection->errorMessage));
                    return;

                case pq\Connection::POLLING_OK:
                    $deferred->resolve(new self($connection));
                    return;
            }
        };

        $poll = Loop::onReadable($connection->socket, $callback);
        $await = Loop::onWritable($connection->socket, $callback);

        $promise = $deferred->promise();

        $token = $token ?? new NullCancellationToken();
        $id = $token->subscribe([$deferred, "fail"]);

        $promise->onResolve(function () use ($poll, $await, $id, $token) {
            $token->unsubscribe($id);
            Loop::cancel($poll);
            Loop::cancel($await);
        });

        return $promise;
    }