<commit_before>define([
	"dojo/_base/declare", "dojo/_base/lang", "dijit/_WidgetBase",
	"dojo/on", "dojo/dom-class",
	"./SummaryWidget", "./D3StackedBarChart"

], function(declare, lang, WidgetBase,
			on, domClass,
			SummaryWidget, D3StackedBarChart){

	var phenotypeDef = {
		"Resistant": 0,
		"Susceptible": 1,
		"Intermediate": 2
	};

	return declare([SummaryWidget], {
		dataModel: "genome_amr",
		query: "",
		baseQuery: "&in(resistant_phenotype,(Resistant,Susceptible,Intermediate))&limit(1)&facet((pivot,(antibiotic,resistant_phenotype)),(mincount,1),(limit,-1))&json(nl,map)",
		columns: [{
			label: "Antibiotic",
			field: "antibiotic"
		}, {
			label: "Susceptible",
			field: "Susceptible"
		}, {
			label: "Intermediate",
			field: "Intermediate"
		}, {
			label: "Resistant",
			field: "Resistant"
		}],
		processData: function(data){

			if(!data || !data.facet_counts || !data.facet_counts.facet_pivot || !data.facet_counts.facet_pivot['antibiotic,resistant_phenotype']){
				console.log("INVALID SUMMARY DATA", data);
				return;
			}

			// control based on data availability
			if(data.response.numFound === 0){
				domClass.add(this.domNode.parentNode, "hidden");
				return;
			}else{
				domClass.remove(this.domNode.parentNode, "hidden");
			}

			var antibiotic_data = data.facet_counts.facet_pivot['antibiotic,resistant_phenotype'];

			var chartData = [];
			var tableData = [];

			antibiotic_data.forEach(function(d){
				var antibiotic = d.value;
				if(d.pivot){
					// process table data
					var item = {antibiotic: antibiotic};
					d.pivot.forEach(function(phenotype){
						item[phenotype.value] = phenotype.count;
					});
					tableData.push(item);

					// process chart data
					var dist = [0, 0, 0];
					d.pivot.forEach(function(phenotype){
						if(phenotypeDef.hasOwnProperty(phenotype.value)){
							dist[phenotypeDef[phenotype.value]] = phenotype.count;
						}
					});
					var total = dist.reduce(function(a, b){
						return a + b;
					});

					chartData.push({
						label: antibiotic,
						phenotypes: ["Resistant", "Susceptible", "Intermediate"],
						total: total,
						dist: dist
					});
				}
			});
			// console.log(chartData, tableData);
			this._tableData = tableData;

			this.set('data', chartData);<commit_msg>resolve #882. count unique genome id<commit_after>define([
	"dojo/_base/declare", "dojo/_base/lang", "dijit/_WidgetBase",
	"dojo/on", "dojo/dom-class",
	"./SummaryWidget", "./D3StackedBarChart"

], function(declare, lang, WidgetBase,
			on, domClass,
			SummaryWidget, D3StackedBarChart){

	var phenotypeDef = {
		"Resistant": 0,
		"Susceptible": 1,
		"Intermediate": 2
	};

	return declare([SummaryWidget], {
		dataModel: "genome_amr",
		query: "",
		baseQuery: "&in(resistant_phenotype,(Resistant,Susceptible,Intermediate))&limit(1)&facet((pivot,(antibiotic,resistant_phenotype,genome_id)),(mincount,1),(limit,-1))&json(nl,map)",
		columns: [{
			label: "Antibiotic",
			field: "antibiotic"
		}, {
			label: "Susceptible",
			field: "Susceptible"
		}, {
			label: "Intermediate",
			field: "Intermediate"
		}, {
			label: "Resistant",
			field: "Resistant"
		}],
		processData: function(data){

			if(!data || !data.facet_counts || !data.facet_counts.facet_pivot || !data.facet_counts.facet_pivot['antibiotic,resistant_phenotype,genome_id']){
				console.log("INVALID SUMMARY DATA", data);
				return;
			}

			// control based on data availability
			if(data.response.numFound === 0){
				domClass.add(this.domNode.parentNode, "hidden");
				return;
			}else{
				domClass.remove(this.domNode.parentNode, "hidden");
			}

			var antibiotic_data = data.facet_counts.facet_pivot['antibiotic,resistant_phenotype,genome_id'];

			var chartData = [];
			var tableData = [];

			antibiotic_data.forEach(function(d){
				var antibiotic = d.value;
				if(d.pivot){
					// process table data
					var item = {antibiotic: antibiotic};
					d.pivot.forEach(function(phenotype){
						item[phenotype.value] = phenotype.pivot.length;
					});
					tableData.push(item);

					// process chart data
					var dist = [0, 0, 0];
					d.pivot.forEach(function(phenotype){
						if(phenotypeDef.hasOwnProperty(phenotype.value)){
							dist[phenotypeDef[phenotype.value]] = phenotype.pivot.length;
						}
					});
					var total = dist.reduce(function(a, b){
						return a + b;
					});

					chartData.push({
						label: antibiotic,
						phenotypes: ["Resistant", "Susceptible", "Intermediate"],
						total: total,
						dist: dist
					});
				}
			});
			// console.log(chartData, tableData);
			this._tableData = tableData;

			this.set('data', chartData);
{'fraction_non_alphanumeric': 0.16037124973019642, 'fraction_numerical': 0.005827757392618174, 'mean_word_length': 3.6479438314944836, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '1777302', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1557, 'n_words': 264}