﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="7F4FE294-6017-4091-9965-8C4327D2BCAF" codekey="ERGODirekt_Fragenstatistik" categoryCodekey="TestsAndQuestions" name="Fragenstatistik (Single / Multiple Choice) je Test und Zielgruppe" description="Der Report listet für eine gewählte  Zielgruppe und einen gewähltenTest alle Single-/Multiple-Choice-Fragen, die von Nutzern der Zielgruppe bei Ausführung des Test bearbeitet wurden. Dabei wird jeweils die Anzahl, wie oft die Frage bearbeitet wurde und Details zu den einzelnen Anworten ausgegeben.">
      <MetaData created="2016-09-30T09:29:20" createdBy="Administrator TestAllFeatures (Administrator)" createdBy_user_id="12" modified="2016-09-30T09:42:53" modifiedBy="Administrator TestAllFeatures" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="c5fd8bcc-2b1a-4f1d-b30d-9063c3f768cc" mandatorName="ERGODirekt" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="a5485539-67e0-4912-8255-8081a54efb3c" isRequired="True" allowMultiSelect="False" name="TargetGroup" contextName="TargetGroup" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="8dc2cd19-6d97-45c7-a52b-740a2cf7764b" isRequired="True" allowMultiSelect="False" name="Test abhängig vom Zielgruppe" contextName="Test abhängig vom Zielgruppe" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>
        CREATE TABLE #Result
        (
        id INT IDENTITY(1,1),
        type INT,
        numberSuffix INT,
        lernzielname_intern varchar(512),
        question_Id UNIQUEIDENTIFIER,
        answered_Count INT,
        correct_count INT,
        not_answered_Count INT,
        answerA_Count INT,
        answerB_Count INT,
        answerC_Count INT,
        answerD_Count INT,
        answerE_Count INT,
        answerF_Count INT,
        divisionByZero INT
        )
       
        INSERT INTO #Result
        SELECT
          (SELECT type FROM tblTasQuestions WHERE id=tblTasStatsTestSessionQuestions.question_id) type,
          (SELECT numberSuffix FROM tblTasQuestions WHERE id=tblTasStatsTestSessionQuestions.question_id) numberSuffix,
          (SELECT res.Text FROM
	          tblTasQuestionCategoryQuestions qcq
	          INNER JOIN tblTasQuestionCategories qc on qc.id = qcq.category_id
	          INNER JOIN tblTasQuestionCategoriesLearningTarget qclt on qc.id = qclt.questionCategory_id
	          INNER JOIN tblResources res on qc.name_resource_id = res.id and Language_ID=1031
           WHERE tblTasStatsTestSessionQuestions.question_id = qcq.question_id
          ) AS lernzielname_intern,
          tblTasStatsTestSessionQuestions.question_id AS question_Id,
          
          (select COUNT(correct) from tblTasStatsTestSessionQuestions t1
            INNER JOIN tblTasStatsTestSessions ON t1.testsession_id = tblTasStatsTestSessions.testsession_id
            INNER JOIN tblTasTests ON tblTasStatsTestSessions.test_id = tblTasTests.id
	          INNER JOIN tblUsersTargetGroups tg on tg.UserCn=tblTasStatsTestSessions.user_id
          where t1.question_Id = tblTasStatsTestSessionQuestions.question_id
            AND tblTasStatsTestSessions.visible = 1
            AND tg.targetGroup_id = @targetGroup_id
	          AND tblTasTests.id = @test_id
            AND tblTasTests.mode = 1
          )
          AS answered_Count,
          
          (select SUM(correct) from tblTasStatsTestSessionQuestions t1
            INNER JOIN tblTasStatsTestSessions ON t1.testsession_id = tblTasStatsTestSessions.testsession_id
            INNER JOIN tblTasTests ON tblTasStatsTestSessions.test_id = tblTasTests.id
	          INNER JOIN tblUsersTargetGroups tg on tg.UserCn=tblTasStatsTestSessions.user_id
          where t1.question_Id = tblTasStatsTestSessionQuestions.question_id
            AND tblTasStatsTestSessions.visible = 1
            AND tg.targetGroup_id = @targetGroup_id
	          AND tblTasTests.id = @test_id
            AND tblTasTests.mode = 1
          )
          AS correct_Count,
          
          SUM( CASE WHEN answer_index IS NULL THEN 1 ELSE 0 END) AS not_answered_Count,
          SUM( CASE WHEN answer_index=1 THEN 1 ELSE 0 END) AS answerA_Count,
          SUM( CASE WHEN answer_index=2 THEN 1 ELSE 0 END) AS answerB_Count,
          SUM( CASE WHEN answer_index=3 THEN 1 ELSE 0 END) AS answerC_Count,
          SUM( CASE WHEN answer_index=4 THEN 1 ELSE 0 END) AS answerD_Count,
          SUM( CASE WHEN answer_index=5 THEN 1 ELSE 0 END) AS answerE_Count,
          SUM( CASE WHEN answer_index=6 THEN 1 ELSE 0 END) AS answerF_Count,
          0 AS divisionByZero
        FROM  tblTasStatsTestSessionQuestions
          INNER JOIN tblTasQuestions ON tblTasStatsTestSessionQuestions.question_id = tblTasQuestions.id
          INNER JOIN tblTasStatsTestSessions ON tblTasStatsTestSessionQuestions.testsession_id = tblTasStatsTestSessions.testsession_id
          INNER JOIN tblTasTests ON tblTasStatsTestSessions.test_id = tblTasTests.id
	        INNER JOIN tblUsersTargetGroups tg on tg.UserCn=tblTasStatsTestSessions.user_id
          LEFT JOIN tblTasStatsQuestionsChoice ON (tblTasStatsTestSessionQuestions.testsession_id=tblTasStatsQuestionsChoice.testsession_id AND tblTasStatsTestSessionQuestions.question_id=tblTasStatsQuestionsChoice.question_id AND tblTasStatsQuestionsChoice.selected=1)
        WHERE
          tblTasStatsTestSessions.visible = 1
          AND tg.targetGroup_id = @targetGroup_id
	        AND tblTasTests.id = @test_id
          AND tblTasTests.mode = 1
          AND dbo.tblTasQuestions.deleted IS NULL
          AND tblTasQuestions.mandator_id = @current_mandator_id
          AND tblTasQuestions.type in (1,3) -- only SingleChoice and MultipleChoice
        GROUP BY tblTasStatsTestSessionQuestions.question_id

        -- correct not answered count due to missing entries
        update #Result set not_answered_Count = answered_Count - correct_Count where not_answered_Count &gt; answered_Count - correct_Count

        -- prevent division by zero 
        update #Result
        set divisionByZero = 1
        where 
          answered_Count = 0

        SELECT 
            numberSuffix as 'Fragennummer',
            lernzielname_intern as 'Lernziel',
            answered_Count as 'Wie oft beantwortet',
            correct_count as 'Wie oft richtig beantwortet',
            cast(answerA_Count as NVARCHAR(10)) + ' [' + cast(100*answerA_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as '(a)',
            cast(answerB_Count as NVARCHAR(10)) + ' [' + cast(100*answerB_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as '(b)',
            cast(answerC_Count as NVARCHAR(10)) + ' [' + cast(100*answerC_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as '(c)',
            cast(answerD_Count as NVARCHAR(10)) + ' [' + cast(100*answerD_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as '(d)',
            cast(answerE_Count as NVARCHAR(10)) + ' [' + cast(100*answerE_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as '(e)',
            cast(answerF_Count as NVARCHAR(10)) + ' [' + cast(100*answerF_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as '(f)',
            cast(not_answered_Count as NVARCHAR(10)) + ' [' + cast(100*not_answered_Count/(divisionByZero + answered_Count) as NVARCHAR(10)) + '%]' as 'Keine Anwort gegeben'
        FROM  #Result
        ORDER BY numberSuffix
        DROP TABLE  #Result
      </command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="a5485539-67e0-4912-8255-8081a54efb3c" isSystem="True" name="Zielgruppe" reportParameterType_id="4123c2c2-d408-476a-82bf-ca77f9ecf944" queryParameterName="@targetGroup_id" />
    <Parameter id="8dc2cd19-6d97-45c7-a52b-740a2cf7764b" isSystem="True" name="Test abhängig vom Zielgruppe" reportParameterType_id="897a2480-ce48-4746-9773-31b723c715a9" queryParameterName="@test_id" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="4123c2c2-d408-476a-82bf-ca77f9ecf944" isSystem="False" name="TargetGroup" datatype="IntegerDDL" dataValueField="id" dataTextField="title">
      <query>
        SELECT id, title
        FROM tblTargetGroups
        WHERE(mandator_id = @current_mandator_id)
        AND (EXISTS(SELECT * FROM v_Users WHERE intUserCn = @current_user_id AND securityId = 100)
        OR EXISTS(SELECT * FROM tblTargetGroupManagers WHERE tblTargetGroupManagers.user_id = @current_user_id
                  AND tblTargetGroupManagers.targetGroup_id = tblTargetGroups.id)
        OR EXISTS(SELECT *
                  FROM tblRolesFunctions
                  JOIN tblRoles ON tblRoles.id = tblRolesFunctions.role_id
                  JOIN tblFunctions ON tblFunctions.id = tblRolesFunctions.function_id
                  JOIN v_Users ON v_Users.intUserCn = @current_user_id
                  WHERE tblFunctions.shortcut = 'FcnIsAuthorizedForAllTGs' AND tblRoles.id = v_Users.SecurityID))
        AND defaultforlibrary = 0
        ORDER BY title
      </query>
    </ParameterType>
    <ParameterType id="897a2480-ce48-4746-9773-31b723c715a9" isSystem="False" name="Test abhängig vom Zielgruppe Typ" datatype="GuidDDL" dataValueField="id" dataTextField="title">
      <query>
        SELECT DISTINCT tblItems.id,
        tblItems.title
        FROM tblItems
        inner JOIN tblModuleItems ON tblModuleItems.item_id = tblItems.id AND tblItems.itemType_id = 0 
        inner JOIN tblEduOffersModules ON tblModuleItems.module_id = tblEduOffersModules.module_id
        inner JOIN tblEduOffersTargetGroups ON tblEduOffersTargetGroups.eduOffer_id = tblEduOffersModules.eduOffer_id
        WHERE tblEduOffersTargetGroups.targetGroup_id = @targetGroup_id
      </query>
      <Parameters>
        <Parameter id="a5485539-67e0-4912-8255-8081a54efb3c" isRequired="False" allowMultiSelect="False" name="Zielgruppe" contextName="Zielgruppe" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
  </ParameterTypes>
</ReportsExport>