Search in sources :

Example 1 with CalendarEvent

use of io.altanalytics.domain.calendar.CalendarEvent in project bibot by alfintech.

the class ElasticPublisher method publishEvents.

@Override
public void publishEvents(List<CalendarEvent> calendarEvents) throws IOException {
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    Date currentTime = Calendar.getInstance().getTime();
    for (CalendarEvent calendarEvent : calendarEvents) {
        System.out.println(calendarEvent);
        for (String currency : calendarEvent.getCurrencies()) {
            XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("eventId", calendarEvent.getEventId()).field("currency", currency).field("title", calendarEvent.getTitle()).field("eventDate", calendarEvent.getEventDate()).field("createdDate", calendarEvent.getCreatedDate()).field("voteCount", calendarEvent.getVoteCount()).field("positiveVoteCount", calendarEvent.getPositiveVoteCount()).field("percentagePositiveVoteCount", calendarEvent.getPercentagePositiveVoteCount()).field("insertionDate", currentTime).endObject();
            String idAsString = new Long(calendarEvent.getEventId()).toString();
            bulkRequest.add(client.prepareIndex("calendarevents", "minutely", idAsString).setSource(builder));
        }
    }
    BulkResponse response = bulkRequest.get();
    LOG.debug(response.toString());
}
Also used : CalendarEvent(io.altanalytics.domain.calendar.CalendarEvent) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) Date(java.util.Date) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with CalendarEvent

use of io.altanalytics.domain.calendar.CalendarEvent in project bibot by alfintech.

the class CoinMarketCalClient method parseResponse.

@SuppressWarnings("unchecked")
private List<CalendarEvent> parseResponse(String response) throws Exception {
    List<CalendarEvent> events = new ArrayList<CalendarEvent>();
    JSONParser jsonParser = new JSONParser();
    JSONArray jsonArray = (JSONArray) jsonParser.parse(response);
    for (Object uncastedResult : jsonArray.toArray(new JSONObject[] {})) {
        JSONObject result = (JSONObject) uncastedResult;
        Long eventId = (Long) result.get(JSON_FIELD_ID);
        Date eventDate = DATE_FORMAT.parse((String) result.get(JSON_FIELD_DATA_EVENT_DATE));
        Date createdDate = DATE_FORMAT.parse((String) result.get(JSON_FIELD_DATA_CREATED_DATE));
        String title = (String) result.get(JSON_FIELD_TITLE);
        String description = (String) result.get(JSON_FIELD_DATA_DESCRIPTION);
        Long voteCount = (Long) result.get(JSON_FIELD_DATA_VOTE_COUNT);
        Long positiveVoteCount = (Long) result.get(JSON_FIELD_DATA_POSITIVE_VOTE_COUNT);
        Long percentagePositive = (Long) result.get(JSON_FIELD_DATA_PERCENTAGE_POSITIVE);
        List<String> currencies = parseCurrencies(result);
        events.add(new CalendarEvent(eventId, currencies, title, description, eventDate, createdDate, voteCount, positiveVoteCount, percentagePositive));
    }
    return events;
}
Also used : JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) CalendarEvent(io.altanalytics.domain.calendar.CalendarEvent) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) Date(java.util.Date)

Aggregations

CalendarEvent (io.altanalytics.domain.calendar.CalendarEvent)2 Date (java.util.Date)2 ArrayList (java.util.ArrayList)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1