Search in sources :

Example 6 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class ApplicationOpenedEventDaoTest method testReadAllByDevice.

@Test
public void testReadAllByDevice() {
    Device device = new Device();
    device.setDeviceId("bcaef51200ac6d92bdd81");
    deviceDao.create(device);
    List<ApplicationOpenedEvent> applicationOpenedEvents = applicationOpenedEventDao.readAll(device);
    assertThat(applicationOpenedEvents.size(), is(0));
    ApplicationOpenedEvent applicationOpenedEvent1 = new ApplicationOpenedEvent();
    applicationOpenedEvent1.setDevice(device);
    applicationOpenedEventDao.create(applicationOpenedEvent1);
    ApplicationOpenedEvent applicationOpenedEvent2 = new ApplicationOpenedEvent();
    applicationOpenedEventDao.create(applicationOpenedEvent2);
    applicationOpenedEvents = applicationOpenedEventDao.readAll(device);
    assertThat(applicationOpenedEvents.size(), is(1));
}
Also used : Device(ai.elimu.model.Device) ApplicationOpenedEvent(ai.elimu.model.analytics.ApplicationOpenedEvent) Test(org.junit.Test)

Example 7 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class DeviceDaoTest method testStoreNearbyDevices.

@Test
public void testStoreNearbyDevices() {
    Device device = new Device();
    device.setDeviceId("aaabbbccc111222333");
    deviceDao.create(device);
    assertThat(device.getDevicesNearby().size(), is(0));
    Set<Device> nearbyDevices = new HashSet<>();
    Device nearbyDevice1 = new Device();
    nearbyDevice1.setDeviceId("dddeeefff444555666");
    deviceDao.create(nearbyDevice1);
    nearbyDevices.add(nearbyDevice1);
    Device nearbyDevice2 = new Device();
    nearbyDevice2.setDeviceId("ggghhhiii777888999");
    deviceDao.create(nearbyDevice2);
    nearbyDevices.add(nearbyDevice2);
    device.setDevicesNearby(nearbyDevices);
    deviceDao.update(device);
    assertThat(device.getDevicesNearby().size(), is(2));
}
Also used : Device(ai.elimu.model.Device) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class ApplicationOpenedEventListController method generateEvents.

private List<ApplicationOpenedEvent> generateEvents(Locale locale) {
    logger.info("generateEvents");
    List<ApplicationOpenedEvent> applicationOpenedEvents = new ArrayList<>();
    String[] eventFiles = new String[] { "application_opened_events_2017-05-25.log", "application_opened_events_2017-05-27.log", "application_opened_events_2017-05-28.log", "application_opened_events_2017-05-29.log", "application_opened_events_2017-05-30.log", "application_opened_events_2017-06-02.log", "application_opened_events_2017-06-03.log", "application_opened_events_2017-06-04.log", "application_opened_events_2017-06-05.log", "application_opened_events_2017-06-06.log", "application_opened_events_2017-06-07.log", "application_opened_events_2017-06-08.log", "application_opened_events_2017-06-09.log" };
    for (String eventFile : eventFiles) {
        logger.info("eventFile: " + eventFile);
        URL url = getClass().getResource(eventFile);
        try {
            Reader reader = new FileReader(url.getFile());
            List<String> lines = IOUtils.readLines(reader);
            logger.info("lines.size(): " + lines.size());
            reader.close();
            for (String eventLine : lines) {
                logger.info("eventLine: " + eventLine);
                // Expected format: id:163|deviceId:2312aff4939750ea|time:1496843219926|packageName:ai.elimu.nyaqd|studentId:2312aff4939750ea_4
                String deviceId = EventLineHelper.getDeviceId(eventLine);
                Device device = deviceDao.read(deviceId);
                logger.info("device: " + device);
                if (device == null) {
                    device = new Device();
                    device.setDeviceId(deviceId);
                    device.setDeviceManufacturer("asdf");
                    device.setDeviceModel("asdf");
                    device.setDeviceSerial("asdf");
                    device.setRemoteAddress("0.0.0.0");
                    device.setOsVersion(23);
                    device.setLocale(locale);
                    deviceDao.create(device);
                }
                Calendar timeOfEvent = EventLineHelper.getTime(eventLine);
                String packageName = EventLineHelper.getPackageName(eventLine);
                ApplicationOpenedEvent existingApplicationOpenedEvent = applicationOpenedEventDao.read(device, timeOfEvent, packageName);
                logger.info("existingApplicationOpenedEvent: " + existingApplicationOpenedEvent);
                if (existingApplicationOpenedEvent == null) {
                    ApplicationOpenedEvent applicationOpenedEvent = new ApplicationOpenedEvent();
                    applicationOpenedEvent.setDevice(device);
                    applicationOpenedEvent.setCalendar(timeOfEvent);
                    applicationOpenedEvent.setPackageName(packageName);
                    applicationOpenedEventDao.create(applicationOpenedEvent);
                    applicationOpenedEvents.add(applicationOpenedEvent);
                }
            }
        } catch (FileNotFoundException ex) {
            logger.error(null, ex);
        } catch (IOException ex) {
            logger.error(null, ex);
        }
    }
    return applicationOpenedEvents;
}
Also used : Device(ai.elimu.model.Device) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) FileReader(java.io.FileReader) IOException(java.io.IOException) URL(java.net.URL) ApplicationOpenedEvent(ai.elimu.model.analytics.ApplicationOpenedEvent) FileReader(java.io.FileReader)

Example 9 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class ApplicationOpenedEventRestController method create.

@RequestMapping("/create")
public String create(HttpServletRequest request, // TODO: checksum,
@RequestParam MultipartFile multipartFile) {
    logger.info("create");
    logger.info("request.getQueryString(): " + request.getQueryString());
    if (!multipartFile.isEmpty()) {
        try {
            byte[] bytes = multipartFile.getBytes();
            Reader reader = new CharSequenceReader((new String(bytes)));
            List<String> lines = IOUtils.readLines(reader);
            logger.info("lines.size(): " + lines.size());
            reader.close();
            for (String eventLine : lines) {
                logger.info("eventLine: " + eventLine);
                // Expected format: id:163|deviceId:2312aff4939750ea|time:1496843219926|packageName:ai.elimu.nyaqd|studentId:2312aff4939750ea_4
                String deviceId = EventLineHelper.getDeviceId(eventLine);
                Device device = deviceDao.read(deviceId);
                logger.info("device: " + device);
                Calendar timeOfEvent = EventLineHelper.getTime(eventLine);
                String packageName = EventLineHelper.getPackageName(eventLine);
                ApplicationOpenedEvent existingApplicationOpenedEvent = applicationOpenedEventDao.read(device, timeOfEvent, packageName);
                logger.info("existingApplicationOpenedEvent: " + existingApplicationOpenedEvent);
                if (existingApplicationOpenedEvent == null) {
                    ApplicationOpenedEvent applicationOpenedEvent = new ApplicationOpenedEvent();
                    applicationOpenedEvent.setDevice(device);
                    applicationOpenedEvent.setCalendar(timeOfEvent);
                    applicationOpenedEvent.setPackageName(packageName);
                    applicationOpenedEventDao.create(applicationOpenedEvent);
                }
            }
        } catch (IOException ex) {
            logger.error(null, ex);
        }
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    // TODO: handle error
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : CharSequenceReader(org.apache.commons.io.input.CharSequenceReader) JSONObject(org.json.JSONObject) Device(ai.elimu.model.Device) Calendar(java.util.Calendar) ApplicationOpenedEvent(ai.elimu.model.analytics.ApplicationOpenedEvent) Reader(java.io.Reader) CharSequenceReader(org.apache.commons.io.input.CharSequenceReader) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class LetterLearningEventDaoTest method testReadAllByDevice.

@Test
public void testReadAllByDevice() {
    Device device = new Device();
    device.setDeviceId("ddhe72a08347cd29bd3f43d");
    deviceDao.create(device);
    List<LetterLearningEvent> letterLearningEvents = letterLearningEventDao.readAll(device);
    assertThat(letterLearningEvents.size(), is(0));
    Letter letter = new Letter();
    letter.setText("a");
    letterDao.create(letter);
    LetterLearningEvent letterLearningEvent = new LetterLearningEvent();
    letterLearningEvent.setDevice(device);
    letterLearningEvent.setLetter(letter);
    letterLearningEventDao.create(letterLearningEvent);
    letterLearningEvents = letterLearningEventDao.readAll(device);
    assertThat(letterLearningEvents.size(), is(1));
    assertThat(letterLearningEvents.get(0).getLetter().getText(), is("a"));
}
Also used : Letter(ai.elimu.model.content.Letter) Device(ai.elimu.model.Device) LetterLearningEvent(ai.elimu.model.analytics.LetterLearningEvent) Test(org.junit.Test)

Aggregations

Device (ai.elimu.model.Device)12 Test (org.junit.Test)7 ApplicationOpenedEvent (ai.elimu.model.analytics.ApplicationOpenedEvent)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 HashSet (java.util.HashSet)3 JSONObject (org.json.JSONObject)3 Student (ai.elimu.model.Student)2 DeviceGson (ai.elimu.model.gson.DeviceGson)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 Calendar (java.util.Calendar)2 Contributor (ai.elimu.model.Contributor)1 LetterLearningEvent (ai.elimu.model.analytics.LetterLearningEvent)1 NumberLearningEvent (ai.elimu.model.analytics.NumberLearningEvent)1 Letter (ai.elimu.model.content.Letter)1 Number (ai.elimu.model.content.Number)1 Locale (ai.elimu.model.enums.Locale)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1