use of com.google.gson.JsonPrimitive in project iosched by google.
the class DataExtractor method setVideoForVideoSession.
private JsonPrimitive setVideoForVideoSession(JsonObject origin, JsonObject dest) {
JsonPrimitive vid = getVideoFromTopicInfo(origin, InputJsonKeys.VendorAPISource.Topics.INFO_VIDEO_URL, null);
if (vid != null) {
set(vid, dest, OutputJsonKeys.VideoLibrary.vid);
JsonPrimitive thumbnail = new JsonPrimitive("http://img.youtube.com/vi/" + vid.getAsString() + "/hqdefault.jpg");
set(thumbnail, dest, OutputJsonKeys.VideoLibrary.thumbnailUrl);
}
return vid;
}
use of com.google.gson.JsonPrimitive in project iosched by google.
the class DataExtractor method isLivestreamed.
private boolean isLivestreamed(JsonObject sessionObj) {
// data generated after the end of the conference should never have livestream URLs
long endOfConference = Config.CONFERENCE_DAYS[Config.CONFERENCE_DAYS.length - 1][1];
if (System.currentTimeMillis() > endOfConference) {
return false;
}
JsonPrimitive livestream = getMapValue(get(sessionObj, InputJsonKeys.VendorAPISource.Topics.Info), InputJsonKeys.VendorAPISource.Topics.INFO_IS_LIVE_STREAM, null, null);
return livestream != null && "true".equalsIgnoreCase(livestream.getAsString());
}
use of com.google.gson.JsonPrimitive in project iosched by google.
the class DataExtractor method extractRooms.
public JsonArray extractRooms(JsonDataSources sources) {
HashSet<String> ids = new HashSet<String>();
JsonArray result = new JsonArray();
JsonDataSource source = sources.getSource(InputJsonKeys.VendorAPISource.MainTypes.rooms.name());
if (source != null) {
for (JsonObject origin : source) {
JsonObject dest = new JsonObject();
JsonElement originalId = get(origin, InputJsonKeys.VendorAPISource.Rooms.Id);
String id = Config.ROOM_MAPPING.getRoomId(originalId.getAsString());
if (!ids.contains(id)) {
String title = Config.ROOM_MAPPING.getTitle(id, get(origin, InputJsonKeys.VendorAPISource.Rooms.Name).getAsString());
set(new JsonPrimitive(id), dest, OutputJsonKeys.Rooms.id);
set(originalId, dest, OutputJsonKeys.Rooms.original_id);
set(new JsonPrimitive(title), dest, OutputJsonKeys.Rooms.name);
result.add(dest);
ids.add(id);
}
}
}
if (Config.DEBUG_FIX_DATA) {
DebugDataExtractorHelper.changeRooms(result);
}
return result;
}
use of com.google.gson.JsonPrimitive in project iosched by google.
the class DebugDataExtractorHelper method changeRooms.
public static final void changeRooms(JsonArray allRooms) {
for (String room : rooms) {
JsonObject dest = new JsonObject();
JsonPrimitive roomId = new JsonPrimitive(room);
JsonPrimitive roomName = new JsonPrimitive("Room " + room);
DataModelHelper.set(roomId, dest, OutputJsonKeys.Rooms.id);
DataModelHelper.set(roomName, dest, OutputJsonKeys.Rooms.name);
allRooms.add(dest);
}
}
use of com.google.gson.JsonPrimitive in project iosched by google.
the class DebugDataExtractorHelper method changeSession.
public static final void changeSession(JsonObject session, Set<String> usedTags) {
int hash = session.get(OutputJsonKeys.Sessions.id.name()).getAsString().hashCode();
r.setSeed(hash);
// timeslot:
int day = days[uniform(2)];
int[] timeSlot = sessionTimes[uniform(sessionTimes.length)];
Calendar start = new GregorianCalendar(2014, Calendar.JUNE, day, timeSlot[0], timeSlot[1], 0);
Calendar end = new GregorianCalendar(2014, Calendar.JUNE, day, timeSlot[2], timeSlot[3], 0);
long offset = TimeZone.getTimeZone("PST").getOffset(start.getTimeInMillis());
start.setTimeInMillis(start.getTimeInMillis() - offset);
end.setTimeInMillis(end.getTimeInMillis() - offset);
String startS = formatter.format(start.getTime());
String endS = formatter.format(end.getTime());
DataModelHelper.set(new JsonPrimitive(startS), session, OutputJsonKeys.Sessions.startTimestamp);
DataModelHelper.set(new JsonPrimitive(endS), session, OutputJsonKeys.Sessions.endTimestamp);
// Room:
DataModelHelper.set(new JsonPrimitive(rooms[uniform(rooms.length)]), session, OutputJsonKeys.Sessions.room);
JsonArray tags = new JsonArray();
// 2 random topic tags
// not the most efficient, but good enough and avoid duplicates
Collections.shuffle(topicTags, r);
if (topicTags.size() > 0)
tags.add(topicTags.get(0).get(OutputJsonKeys.Tags.tag.name()));
if (topicTags.size() > 1)
tags.add(topicTags.get(1).get(OutputJsonKeys.Tags.tag.name()));
// 1 randomly distributed theme tag
tags.add(themeTags[roullette(themeDistribution)].get(OutputJsonKeys.Tags.tag.name()));
// 1 randomly distributed type tag
tags.add(typeTags[roullette(typeDistribution)].get(OutputJsonKeys.Tags.tag.name()));
for (JsonElement tag : tags) {
usedTags.add(tag.getAsString());
}
DataModelHelper.set(tags, session, OutputJsonKeys.Sessions.tags);
// Livestream
boolean isLiveStream = uniform(2) == 1;
if (isLiveStream) {
DataModelHelper.set(new JsonPrimitive("https://www.youtube.com/watch?v=dQw4w9WgXcQ"), session, OutputJsonKeys.Sessions.youtubeUrl);
DataModelHelper.set(new JsonPrimitive("http://www.google.com/humans.txt"), session, OutputJsonKeys.Sessions.captionsUrl);
DataModelHelper.set(new JsonPrimitive(Boolean.TRUE), session, OutputJsonKeys.Sessions.isLivestream);
} else {
session.remove(OutputJsonKeys.Sessions.youtubeUrl.name());
session.remove(OutputJsonKeys.Sessions.captionsUrl.name());
DataModelHelper.set(new JsonPrimitive(Boolean.FALSE), session, OutputJsonKeys.Sessions.isLivestream);
}
}
Aggregations