{% extends "base_QC.html" %}

{% import 'pcaReport.html' as pca %}

{% if item.ReportType == 'feature summary' %}
	{% set reportTitle = 'Feature Summary Report' %}
{% elif item.ReportType == 'merge loq assessment' %}
	{% set reportTitle = 'Limits Of Quantification Assessment Report' %}
{% elif item.ReportType == 'final report' %}
	{% set reportTitle = 'Final Report' %}
{% else %}
	{% set reportTitle = 'Summary Report ({{ item.ReportType }})' %}
{% endif %}

{% block title %}{{ reportTitle }} For: {{ item.Name }} {% endblock %}

{% block content %}


<!--Feature summary report - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

{% if item.ReportType == 'feature summary' %}

	<!--Feature Summary-->
	<div class='content'>
		<p>Data consists of {{ item['Nfeatures'] }} features:<p>
		<ul>
			{% for i in item['QTypeIter'] %}
				<li>{{ item['CountQType'][i] }} features {{ item['TextQType'][i] }}.</li>
			{% endfor %}
		</ul>
		</p>
	</div>
	{{ item['FeatureQuantParamTableOverall'].to_html() }}

	<!--Figure 1: Acquisition structure colored by Limits Of Quantification-->
	<p class="caption"><span class="heading">Figure 1.</span> Acquisition structure colored by Limits Of Quantification.</p>
	<div class='figure'>
		<img src="{{ item.AcquisitionStructure }}" alt="Acquisition structure colored by Limits Of Quantification.">
	</div>


	<!--Iterate over Quantification Types-->
	{% for i in item['QTypeIter'] %}

		<!--Title-->
		<h2>Features {{ item['TextQType'][i] }} ({{ item['CountQType'][i] }})</h2>


		<!--Table 1: Feature quantification parameters-->
		<p class="caption"><span class="heading">Table {{ item['figTabNumber']['1'][i] }}.</span> Quantification parameters for features {{ item['TextQType'][i] }}.</p>
		{{ item['FeatureQuantParamTable'][i].to_html() }}


		<!--Figure 2: Feature Accuracy Plot-->
		<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['2'][i] }}.</span> Measurements accuracy for features {{ item['TextQType'][i] }}.</p>
		{% if 'FeatureAccuracyPlot' in item %}
			<div class='figure'>
				<img src="{{ item.FeatureAccuracyPlot[i] }}" alt="Measurements accuracy for features {{ item['TextQType'][i] }}.">
			</div>
		{% else %}
			<p>Unable to calculate (not enough samples with expected concentrations present in dataset).</p>
		{% endif %}


		<!--Figure 3: Feature Precision Plot-->
		{% if 'FeaturePrecisionPlot' in item %}
			<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['3'][i] }}.</span> Measurements precision for features {{ item['TextQType'][i] }}.</p>
			<div class='figure'>
				<img src="{{ item.FeaturePrecisionPlot[i] }}" alt="Measurements precision for features {{ item['TextQType'][i] }}.">
			</div>
		{% elif 'FeatureRSDPlot' in item %}
			<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['3'][i] }}.</span> Measurements RSD for features {{ item['TextQType'][i] }} in all samples (by sample type).</p>
			<div class='figure'>
				<img src="{{ item.FeatureRSDPlot[i] }}" alt="Measurements RSD for features {{ item['TextQType'][i] }} in all samples (by sample type).">
			</div>
		{% else %}
			<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['3'][i] }}.</span> Measurements precision for features {{ item['TextQType'][i] }}.</p>
			<p>Unable to calculate (not enough samples with expected concentrations present in dataset).</p>
		{% endif %}


		<!--Figure 4: Measured concentrations distribution, split by sample types.-->
		<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['4'][i] }}.</span> Measured concentrations distribution, split by sample types, for features {{ item['TextQType'][i] }}.</p>
		<div class='figure'>
			{% for value in item.FeatureConcentrationDistribution[i] %}
				<img src="{{ value }}" alt="Measured concentrations distribution, split by sample types, for features {{ item['TextQType'][i] }}.">
			{% endfor %}
			
		</div>


		<!--Table 2: Feature Accuracy Precision Table-->
		{% if 'FeatureAccPreTable' in item %}
			<p class="caption"><span class="heading">Table {{ item['figTabNumber']['2'][i] }}.</span> Measurement accuracy (%) and precision (% RSD) for features {{ item['TextQType'][i] }}.</p>
			{{ item['FeatureAccPreTable'][i].to_html() }}
		{% elif 'FeatureRSDTable' in item %}
			<p class="caption"><span class="heading">Table {{ item['figTabNumber']['2'][i] }}.</span> RSD for features {{ item['TextQType'][i] }}.</p>
			{{ item['FeatureRSDTable'][i].to_html() }}
		{% else %}
			<p class="caption"><span class="heading">Table {{ item['figTabNumber']['2'][i] }}.</span> Measurement accuracy (%) and precision (% RSD) for features {{ item['TextQType'][i] }}.</p>
			<p>Unable to calculate (not enough samples with expected concentrations present in dataset).</p>
		{% endif %}

	{% endfor %}

{% endif %}


<!-- Batch correction assessment report  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
{% if item.ReportType == 'merge loq assessment' %}

	<!--Intro only present monitored features-->
	<h3>Only quantified features are assessed for the merge of limits of quantification ({{ item['MonitoredFeaturesRatio'] }}).</h3>

	<!--Table 1: Limits of quantification-->
	<p class="caption"><span class="heading">Table 1.</span> Limits of Quantification pre and post merging to the lowest common denominator.</p>
	{{ item['LOQSummaryTable'].to_html() }}

	<!--Table 2: Number of samples <LLOQ-->
	<p class="caption"><span class="heading">Table 2.</span> Number of sample measurements lower than the Lowest Limit of Quantification, pre and post merging to the lowest common denominator.</p>
	{{ item['LLOQSummaryTable'].to_html() }}

	<!--Table 3: Number of samples >ULOQ-->
	<p class="caption"><span class="heading">Table 3.</span> Number of sample measurements greater than the Upper Limit of Quantification, pre and post merging to the lowest common denominator.</p>
	{{ item['ULOQSummaryTable'].to_html() }}

	<!--Figure 1: Measured concentrations pre and post LOQ-->
	<p class="caption"><span class="heading">Figure 1.</span> Measured concentrations pre and post LOQ merge, split by batch and sample types.</p>
	<div class='figure'>
		<div class='figure'>
			{% for value in item.ConcentrationPrePostMergeLOQ %}
				<img src="{{ value }}" alt="Measured concentrations pre and post LOQ merge, split by batch and sample types.">
			{% endfor %}
		
	</div>

{% endif %}


<!-- Final summary report  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

{% if item.ReportType == 'final report' %}

	<!--Overall Summary-->
	<h2>Final Dataset</h2>

	<div class='content'>
		<p>Method: {{ item['TargMethod'] }}</p>
		<p>{{ item['Nsamples'] }} samples</p>
		<p>{{ item['Nfeatures'] }} features</p>
		<ul>
			{% for i in item['QTypeIter'] %}
				<li>{{ item['CountQType'][i] }} features {{ item['TextQType'][i] }}.</li>
			{% endfor %}
		</ul>
		<p></p>
	</div>

	<!--Sample Details-->
	<h2>Sample Summary</h2>

	<!--Summary of samples in final dataset-->
	<h3>Sample Summary Table</h3>
	{{ item['SampleSummaryTable'].to_html() }}

	<div class='content'>
		<p>*Details of any missing samples given at the end of the report</p>
		<p></p>
	</div>

	<!--Acquisition Structure-->
	<h3>Sample Acquisition Structure</h3>

	<div class='content'>
		<p>Samples acquired in {{ item['nBatchesCollect'] }} between {{ item['start'] }} and {{ item['end'] }}</p>
		<p></p>
	</div>

	<!--Figure 1: Acquisition structure colored by Limits Of Quantification-->
	<p class="caption"><span class="heading">Figure 1.</span> Acquisition structure colored by Limits Of Quantification.</p>
	<div class='figure'>
		<img src="{{ item.AcquisitionStructure }}" alt="Acquisition structure colored by Limits Of Quantification.">
	</div>


	<!-- Feature details -->
	<h2>Feature Summary</h2>

	<!--Summary of Features in final dataset-->
	<h3>Feature Summary Table</h3>
	{{ item['FeatureQuantParamTableOverall'].to_html() }}

	<!--Iterate over Quantification Types-->
	{% for i in item['QTypeIter'] %}

		<!--Title-->
		<h2>Features {{ item['TextQType'][i] }} ({{ item['CountQType'][i] }})</h2>


		<!--Table 2: Feature quantification parameters-->
		<p class="caption"><span class="heading">Table {{ item['figTabNumber']['2'][i] }}.</span> Quantification parameters for features {{ item['TextQType'][i] }}.</p>
		{{ item['FeatureQuantParamTable'][i].to_html() }}


		<!--Figure 2: Feature Accuracy Plot-->
		<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['2'][i] }}.</span> Measurements accuracy for features {{ item['TextQType'][i] }}.</p>
		{% if 'FeatureAccuracyPlot' in item %}
			<div class='figure'>
				<img src="{{ item.FeatureAccuracyPlot[i] }}" alt="Measurements accuracy for features {{ item['TextQType'][i] }}.">
			</div>
		{% else %}
			<p>Unable to calculate (not enough samples with expected concentrations present in dataset).</p>
		{% endif %}


		<!--Figure 3: Feature Precision Plot-->
		{% if 'FeaturePrecisionPlot' in item %}
			<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['3'][i] }}.</span> Measurements precision for features {{ item['TextQType'][i] }}.</p>
			<div class='figure'>
				<img src="{{ item.FeaturePrecisionPlot[i] }}" alt="Measurements precision for features {{ item['TextQType'][i] }}.">
			</div>
		{% elif 'FeatureRSDPlot' in item %}
			<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['3'][i] }}.</span> Measurements RSD for features {{ item['TextQType'][i] }} in all samples (by sample type).</p>
			<div class='figure'>
				<img src="{{ item.FeatureRSDPlot[i] }}" alt="Measurements RSD for features {{ item['TextQType'][i] }} in all samples (by sample type).">
			</div>
		{% else %}
			<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['3'][i] }}.</span> Measurements precision for features {{ item['TextQType'][i] }}.</p>
			<p>Unable to calculate (not enough samples with expected concentrations present in dataset).</p>
		{% endif %}


		<!--Figure 4: Measured concentrations distribution, split by sample types.-->
		<p class="caption"><span class="heading">Figure {{ item['figTabNumber']['4'][i] }}.</span> Measured concentrations distribution, split by sample types, for features {{ item['TextQType'][i] }}.</p>
		<div class='figure'>
			{% for value in item.FeatureConcentrationDistribution[i] %}
				<img src="{{ value }}" alt="Measured concentrations pre and post LOQ merge, split by batch and sample types.">
			{% endfor %}
		</div>


		<!--Table 3: Feature Accuracy Precision Table-->
		{% if 'FeatureAccPreTable' in item %}
			<p class="caption"><span class="heading">Table {{ item['figTabNumber']['3'][i] }}.</span> Measurement accuracy (%) and precision (% RSD) for features {{ item['TextQType'][i] }}.</p>
			{{ item['FeatureAccPreTable'][i].to_html() }}
		{% elif 'FeatureRSDTable' in item %}
			<p class="caption"><span class="heading">Table {{ item['figTabNumber']['3'][i] }}.</span> RSD for features {{ item['TextQType'][i] }}.</p>
			{{ item['FeatureRSDTable'][i].to_html() }}
		{% else %}
			<p class="caption"><span class="heading">Table {{ item['figTabNumber']['3'][i] }}.</span> Measurement accuracy (%) and precision (% RSD) for features {{ item['TextQType'][i] }}.</p>
			<p>Unable to calculate (not enough samples with expected concentrations present in dataset).</p>
		{% endif %}

	{% endfor %}


    <!--Multivariate -->
    {% if pcaPlots %}
	    {{ pca.basicPCAReport(pcaPlots)}}
    {% endif %}

	<!--Samples missing from acquisition-->
	{% if 'SamplesMissingInfo' in item %}
		<h2>Samples Missing from Acquisition</h2>
	{% elif 'SamplesExcludedInfo' in item %}
		<h2>Samples Missing from Acquisition</h2>
	{% endif %}

	<!--Summary of samples missing from acquisition-->
	{% if 'SamplesMissingInfo' in item %}
		<h3>Samples unavailable for acquisition</h3>
		{{ item['SamplesMissingInfo'].to_html() }}
	{% endif %}

	{% if 'SamplesExcludedInfo' in item %}
		<h3>Samples excluded on analytical criteria</h3>
		{{ item['SamplesExcludedInfo'].to_html() }}
	{% endif %}

{% endif %}	


{% endblock %}
