/** REST API call to sentiment 140 */ @Override public void execute(Tuple tuple, BasicOutputCollector collector) { startTime = System.currentTimeMillis(); List<Object> otherFields = Lists.newArrayList(tuple.getValues()); int currentCounter = (Integer) otherFields.get(0); int currentSentiment = (Integer) otherFields.get(1); Date tempDate = (Date) otherFields.get(2); // 0: counter, 1: // // sentement_Id, // // 2:Date_object Integer isAnomalous = (Integer) otherFields.get(3); List<TweetTransferEntity> tweetList = (List<TweetTransferEntity>) otherFields.get(4); int aggregation_factor = 123; TweetJDBCTemplate tweetJdbcTemplate = TweetJDBCTemplateConnectionPool.getTweetJDBCTemplate("test", configFile); List<AnomalyTableObject> anomalies = new ArrayList<AnomalyTableObject>(0); if (isAnomalous == 1 || isAnomalous == 2) { // for (TweetTransferEntity tweetTransferEntity : tweetList) { // AnomalyTableObject anomaly = new AnomalyTableObject(); // anomaly.setQuery_id(2); // anomaly.setSentiment(currentSentiment); // anomaly.setTimestamp(tweetTransferEntity.getTimestamp() ); // // anomaly.setTweet_id(tweetTransferEntity.getTimestamp()); // anomaly.setValue(currentCounter); // anomaly.setWindow_length(0); // anomaly.setAggregation(aggregation_factor); // anomaly.setNote(tempDate.toString()); // // anomalies.add(anomaly); // } // tweetJdbcTemplate.insertAnomalies(anomalies); long current_timestamp = tempDate.getTime() / 1000; long previousAggregated_timestamp = AggregateUtilityFunctions.minusMinutesToDate(15, tempDate).getTime() / 1000; AnomalyTableObject anomaly = new AnomalyTableObject(); anomaly.setQuery_id(2); anomaly.setSentiment(currentSentiment); anomaly.setTimestamp(tempDate.getTime() / 1000); anomaly.setTweet_id(current_timestamp); anomaly.setValue(currentCounter); anomaly.setWindow_length(0); anomaly.setAggregation(aggregation_factor); anomaly.setNote(tempDate.toString()); tweetJdbcTemplate.insertAnomaly_test( anomaly, previousAggregated_timestamp, current_timestamp); } long elapsedTime = System.currentTimeMillis() - startTime; LOG.info("Time to process is::" + elapsedTime / 1000 + " for size:: " + tweetList.size()); }
public void insertAnomaly_test( AnomalyTableObject anomaly, long start_timestamp, long end_timestamp) { String sql = "INSERT INTO anomalies_test " + "(query_id, sentiment_id, tweet_id, timestamp," + " aggregation, window_length, value, note, start_timestamp, end_timestamp ) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplateObject.update( sql, new Object[] { anomaly.getQuery_id(), anomaly.getSentiment(), anomaly.getTweet_id(), anomaly.getTimestamp(), anomaly.getAggregation(), anomaly.getWindow_length(), anomaly.getValue(), anomaly.getNote(), start_timestamp, end_timestamp }); }