Search in sources :

Example 1 with StepikMetricsPostQuery

use of org.stepik.api.queries.metrics.StepikMetricsPostQuery in project intellij-plugins by StepicOrg.

the class Metrics method postMetrics.

private static void postMetrics(@NotNull Project project, @NotNull Metric metric, @NotNull MetricsStatus status) {
    executor.schedule(() -> {
        StepikApiClient stepikApiClient;
        stepikApiClient = authAndGetStepikApiClient();
        if (!isAuthenticated()) {
            return;
        }
        final StepikMetricsPostQuery query = stepikApiClient.metrics().post().timestamp(System.currentTimeMillis() / 1000L).tags(metric.getTags()).data(metric.getData()).name("ide_plugin").tags("name", "S_Union").tags("ide_name", ApplicationInfo.getInstance().getVersionName()).data("ide_version", ApplicationInfo.getInstance().getBuild().toString()).data("plugin_version", PluginUtils.getVersion()).data("session", session).tags("status", status);
        StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
        if (projectManager != null) {
            query.data("project_id", projectManager.getUuid()).tags("project_programming_language", projectManager.getDefaultLang().getName()).data("project_manager_version", projectManager.getVersion());
            StudyNode projectRoot = projectManager.getProjectRoot();
            if (projectRoot != null) {
                Class<? extends StudyNode> projectRootClass = projectRoot.getClass();
                query.tags("project_root_class", projectRootClass.getSimpleName()).data("project_root_id", projectRoot.getId());
                query.data("course_id", projectRoot.getCourseId(stepikApiClient));
            }
        }
        query.executeAsync().exceptionally((e) -> {
            String message = String.format("Failed post metric: %s", query.toString());
            logger.warn(message, e);
            return null;
        });
    }, 500, TimeUnit.MILLISECONDS);
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) StepikProjectManager(org.stepik.core.StepikProjectManager) StepikMetricsPostQuery(org.stepik.api.queries.metrics.StepikMetricsPostQuery) StudyNode(org.stepik.core.courseFormat.StudyNode)

Aggregations

StepikApiClient (org.stepik.api.client.StepikApiClient)1 StepikMetricsPostQuery (org.stepik.api.queries.metrics.StepikMetricsPostQuery)1 StepikProjectManager (org.stepik.core.StepikProjectManager)1 StudyNode (org.stepik.core.courseFormat.StudyNode)1 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)1