<commit_before>﻿using System;
using System.Collections.Generic;
using System.Web;
using Newtonsoft.Json.Linq;
using TinCan;
using Extensions = TinCan.Extensions;

namespace AUSimulator.Handlers
{
    public class Sendcmi5Statement : cmi5BaseHandler
    {
        public override void ProcessRequest(HttpContext ct)
        {
            ct.Response.ContentType = "text/plain";

            SetCommonParms(ct.Request.QueryString);

            var sessionId = ct.Request.QueryString["sessionId"];
            var score = ct.Request.QueryString["score"];
            var verbName = ct.Request.QueryString["verb"];
            var success = ct.Request.QueryString["success"];
            var durationParts = ct.Request.QueryString["duration"].Split(':');
            var complete = ct.Request.QueryString["complete"];
            var progress = ct.Request.QueryString["progress"];

            var verb = Getcmi5Verb(verbName);

            var context = new Context
            {
                registration = registration,
                contextActivities = new ContextActivities()
            };

            // All "cmi5 defined" statements MUST have a category with an "id" 
            // of "http://purl.org/xapi/cmi5/context/categories/cmi5". 
            context.contextActivities.category = new List<Activity>
            {
                cmi5ContextActivity()
            };

            // Statements with a results object that include either "success” or "completion” properties 
            // MUST have a category with an "id" of "http://purl.org/xapi/cmi5/context/categories/moveon". 
            // Other statements MUST NOT include the this property.
            if (!string.IsNullOrWhiteSpace(success) || !string.IsNullOrWhiteSpace(complete))
            {
                context.contextActivities.category.Add(new Activity
                {
                    id = new Uri("http://purl.org/xapi/cmi5/context/categories/moveon")
                });
            }

            // All "cmi5 defined" statements must include the sessionId
            context.extensions = new Extensions(JObject.Parse(
                    "{\"http://purl.org/xapi/cmi5/context/extensions/sessionid\": \"" + sessionId + "\"}"
            ));

            var statement = new Statement
            {
                actor = actor,
                verb = verb,
                target = activity,
                context = context,
                timestamp = DateTime.UtcNow
            };

            // Is there a duration value?
            TimeSpan? duration = null;
            if (!string.IsNullOrWhiteSpace(durationParts[0]) ||
                !string.IsNullOrWhiteSpace(durationParts[1]) ||
                !string.IsNullOrWhiteSpace(durationParts[2]))
            {
               duration = new TimeSpan(<commit_msg>Assign statement id per cmi5 spec change<commit_after>﻿using System;
using System.Collections.Generic;
using System.Web;
using Newtonsoft.Json.Linq;
using TinCan;
using Extensions = TinCan.Extensions;

namespace AUSimulator.Handlers
{
    public class Sendcmi5Statement : cmi5BaseHandler
    {
        public override void ProcessRequest(HttpContext ct)
        {
            ct.Response.ContentType = "text/plain";

            SetCommonParms(ct.Request.QueryString);

            var sessionId = ct.Request.QueryString["sessionId"];
            var score = ct.Request.QueryString["score"];
            var verbName = ct.Request.QueryString["verb"];
            var success = ct.Request.QueryString["success"];
            var durationParts = ct.Request.QueryString["duration"].Split(':');
            var complete = ct.Request.QueryString["complete"];
            var progress = ct.Request.QueryString["progress"];

            var verb = Getcmi5Verb(verbName);

            var context = new Context
            {
                registration = registration,
                contextActivities = new ContextActivities()
            };

            // All "cmi5 defined" statements MUST have a category with an "id" 
            // of "http://purl.org/xapi/cmi5/context/categories/cmi5". 
            context.contextActivities.category = new List<Activity>
            {
                cmi5ContextActivity()
            };

            // Statements with a results object that include either "success” or "completion” properties 
            // MUST have a category with an "id" of "http://purl.org/xapi/cmi5/context/categories/moveon". 
            // Other statements MUST NOT include the this property.
            if (!string.IsNullOrWhiteSpace(success) || !string.IsNullOrWhiteSpace(complete))
            {
                context.contextActivities.category.Add(new Activity
                {
                    id = new Uri("http://purl.org/xapi/cmi5/context/categories/moveon")
                });
            }

            // All "cmi5 defined" statements must include the sessionId
            context.extensions = new Extensions(JObject.Parse(
                    "{\"http://purl.org/xapi/cmi5/context/extensions/sessionid\": \"" + sessionId + "\"}"
            ));

            var statement = new Statement
            {
                id = Guid.NewGuid(),
                actor = actor,
                verb = verb,
                target = activity,
                context = context,
                timestamp = DateTime.UtcNow
            };

            // Is there a duration value?
            TimeSpan? duration = null;
            if (!string.IsNullOrWhiteSpace(durationParts[0]) ||
                !string.IsNullOrWhiteSpace(durationParts[1]) ||
                !string.IsNullOrWhiteSpace(durationParts[2]))
            {
               duration = new TimeSpan(
{'fraction_non_alphanumeric': 0.10133006650332517, 'fraction_numerical': 0.005075253762688134, 'mean_word_length': 1.7891654465592972, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3511994', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1402, 'n_words': 319}