Created
September 26, 2013 12:54
-
-
Save andrewconnell/6713755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= | |
# Script: ExtractAssessmentQuestions.ps1 | |
# | |
# Author: Andrew Connell | |
# http://www.AndrewConnell.com | |
# | |
# Description: Extracts assessment questions from a specified course module. | |
# | |
# Parameters: $CourseId - Course ID to extract the questions from. | |
# ex: "sharepoint2013-workflow-fundamentals" | |
# $ModuleId - Module number to extract the questions from. | |
# ex: "1" | |
# Optional Parameters: | |
# $AllModules - Flag indicating if the script should extract questions from all | |
# modules (default = false). | |
# $GenerateQuestionFile - Flag indicating if the assessment question file should be | |
# generated for each module (default=false). | |
# $BuildVersion - Main | Production (default = "Main") | |
# Sample usage: | |
# .\ExtractAssessmentQuestions.ps1 | |
# -$CourseId:"sharepoint2013-workflow-fundamentals" | |
# -ModuleId:1 | |
# -AllModules:$true | |
# -GenerateQuestionFile:$true | |
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= | |
param( | |
[string]$CourseId, | |
[int]$ModuleId, | |
[bool]$AllModules = $false, | |
[bool]$GenerateQuestionFile = $false, | |
[string]$BuildVersion = "Main" | |
) | |
$ErrorActionPreference = 'Stop' | |
# get reference to logging script & load | |
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition | |
$loggerScriptPath = Join-Path -Path $scriptPath -ChildPath "Logger.ps1" | |
. $loggerScriptPath | |
# ----------------------------------------------- | |
# get path to the course | |
$sourcePath = Split-Path -Path $scriptPath -Parent | |
$coursePath = Join-Path -Path $sourcePath -ChildPath $BuildVersion | |
$coursePath = Join-Path -Path $coursePath -ChildPath $CourseId | |
LogInfo "Course Path: $coursePath" | |
# loop through all modules | |
Get-ChildItem -Path $coursePath -Directory | ForEach-Object { | |
$modulePath = $_.FullName | |
LogInfo " . checking Module: $_" | |
# if only doing one module, skip until find the module with the name "[$courseid]-m[$moduleid]-*" | |
if ( ($AllModules -eq $false) -and ($_ -notlike "*-m$ModuleId-*") ){ | |
LogInfo " ... skipping module" | |
Write-Host | |
return | |
} else { | |
Write-Host | |
LogHighlight " Processing module: $_" | |
Write-Host | |
# get path to "\clip-metadata" | |
$clipFolderPath = Join-Path -Path $_.FullName -ChildPath "clip-metadata" | |
# create questions array | |
$questionsFound = @() | |
# open each file and search for a marker that has a <xmp:comment> that starts with "Q)" | |
Get-ChildItem -Path $clipFolderPath -Filter "*.xmp" -File | ForEach-Object { | |
$clipName = $_.BaseName | |
# metadata file | |
$clipMetadataXml = ([xml](Get-Content -Path $_.FullName)) | |
# find all markers in video metadata file | |
$namespaces = @{rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";xmpDM="http://ns.adobe.com/xmp/1.0/DynamicMedia/"} | |
$xPathQuery = "//xmpDM:markers/rdf:Seq/rdf:li" | |
$clipMarkers = Select-Xml -Xml $clipMetadataXml -Namespace $namespaces -XPath $xPathQuery | |
if ($clipMarkers -ne $null){ | |
# loop through all markers | |
$clipMarkers | ForEach-Object { | |
$marker = $_.Node | |
$comment = $marker.comment | |
$timecode = $marker.startTime | |
$timecodeSeconds = 0 | |
$timecodeInSeconds = [Math]::Floor([decimal]([int]$timecode)*(1001/30000)) | |
$timecodeMinutes = [Math]::DivRem([decimal]$timecodeInSeconds,60,[ref]$timecodeSeconds) | |
$timecodeResult = [String]::Format("{0:D2}:{1:D2}", $timecodeMinutes, $timecodeSeconds) | |
if ( ($comment -ne $null) -and ($comment.StartsWith("Q)")) ){ | |
$question = New-Object -TypeName PSCustomObject | |
$question | Add-Member -MemberType NoteProperty -Name "Question" -Value $comment | |
$question | Add-Member -MemberType NoteProperty -Name "Clip" -Value $clipName | |
$question | Add-Member -MemberType NoteProperty -Name "Timecode" -Value $timecodeResult | |
$questionsFound += $question | |
} | |
} | |
} | |
} # open each clip extract file and search for a marker that has a <xmp:comment> that starts with "Q)" | |
# if any questions found | |
if ($questionsFound.Length -gt 0){ | |
LogHighlight " . found $($questionsFound.Length) questions" | |
# if generating quesiton file, overwrite one there with an empty one | |
if ($GenerateQuestionFile -eq $true){ | |
LogInfo " . creating question file in module: questions.txt" | |
$questionsFilePath = Join-Path -Path $modulePath -ChildPath "questions.txt" | |
New-Item -Path $questionsFilePath -ItemType File -Force | Out-Null | |
} | |
# output questions | |
$questionsFound | ForEach-Object { | |
$question = $_ | |
# write out question to log | |
LogHighlight " . Question:" | |
LogHighlight " . @timecode $($question.Timecode)" | |
LogHighlight " . @clip $($question.Clip)" | |
LogInfo " . $($question.Question)" | |
Write-Host | |
# if generating question file, append the question | |
if ($GenerateQuestionFile -eq $true){ | |
$question.Question | Out-File $questionsFilePath -Append | |
"= $($question.Clip).wmv" | Out-File $questionsFilePath -Append | |
"" | Out-File $questionsFilePath -Append | |
} | |
} | |
if ($GenerateQuestionFile -eq $true){ | |
LogSuccess " . question(s) written to question file" | |
} | |
} | |
Write-Host | |
} # if | |
} # </> loop through all modules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment