Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/ProblemPicker.js

/* Author, M. Beeson 
Jan-Feb 2024
This provides a flexible interface to the MathXpert Problem Library,
flexible in the sense that one can easily reorganize the subjects and topics.
Specify your choice of subjects in the array topics33  below.  Then 
the subjects are listed in various named arrays.  You can list your 
desired topics in any desired order in such arrays.
*/  

/* The subjects array is now created dynamically in the selected natural language 
in GetProblem.php.  This example is left here as documentation, to show 
that it is possible to change this structure.  However,  changing it will 
require changing the Engine's response to the askSubjects message; changing it
in a single language would be possible here, but supporting many languages 
is the Engine's job.  

 const subjects = ["Graph Functions", 
                   "Calculus Graphs",
                   "Relations and Inequalities",
                   "Elementary Algebra", 
                   "Linear Algebra", 
                   "Simplify",  
                   "Solve Equations",
                   "Trigonometry", 
                   "Log and Exp", 
                   "Complex Numbers",       
                   "Differentiation and Limits", 
                   "Elementary Integration",
                   "Advanced Differentiation",
                   "Advanced Integration",
                   "Infinite Series"
                   ];

*/ 


const GraphFunctionTopics33=[1,18,19,2,3,4,5,6,7,8,9,10,11,12,13,14,15,28,29];
 
 /*

 #define _ordinary_graph                       1
 #define _compare_same                        18
 #define _compare_different                   19
 #define _ordinary_graph_quadratic             2
 #define _ordinary_graph_polynomial            3
 #define _ordinary_graph_linear                4
 #define _ordinary_graph_rational              5
 #define _ordinary_graph_fractexp              6
 #define _ordinary_graph_exponential           7
 #define _ordinary_graph_log                   8
 #define _ordinary_graph_algvariety            9
 #define _ordinary_graph_sincos               10
 #define _ordinary_graph_trig                 11
 #define _ordinary_graph_arctrig              12
 #define _ordinary_graph_htrig                13
 #define _ordinary_graph_trigvariety          14
 #define _ordinary_graph_bessel               15
 #define _parametric_graph                    28
 #define _polar_graph                         29
 */

const CalculusGraphTopics33 = [30,31,37,38,39,16,17,34,35,36];
 
 /*
 #define _comparefandfprime                   30
 #define _comparetwoderivs                    31
 #define _riemann_sums                        37
 #define _trapezoid_rule                      38
 #define _simpsons_rule                       39
 #define _graph_taylor                        16
 #define _graph_fourier                       17
 #define _solve_ode                           34
 #define _solve_two_odes                      35
 #define _high_order_ode                      36
 */
 
const RelationsAndInequalitiesTopics33 = [20,21,22,23,24,25,26,27];
 /*
 #define _graph_ineq                          20
 #define _graph_set                           21
 #define _graph_circle                        22
 #define _graph_ellipse                       23
 #define _graph_parabola                      24
 #define _graph_hyperbola                     25
 #define _graph_relation                      26
 #define _polyroots                           27
 #define _contour_plot                        32
 #define _complex_contour_plot                33
 */
 
const Algebra1Topics33 = [44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64];
 
 /*
 #define _evaluate_numerically                44
 #define _verify_algebraic_identity           45
 #define _solve_linear_equation               46
 #define _multiply_polynomials                47
 #define _alg1_absolute_value                 48
 #define _numerical_exponents                 49
 #define _alg1_exponents                      50
 #define _simple_factoring                    51
 #define _alg1_factor_quadratic               52
 #define _factor_by_grouping                  53
 #define _complete_the_square                 54
 #define _alg1_linear_inequality              55
 #define _alg1_linear_systems                 56
 #define _alg1_simplify                       57
 #define _add_numerical_fractions             58
 #define _simplify_fractions                  59
 #define _numerical_compound_fractions        60
 #define _alg1_compound_fractions             61
 #define _equations_containing_fractions      62
 #define _numerical_radicals                  63
 #define _alg1_radicals                       64
 */
 
const LinearAlgebraTopics33 = [65,66,67,68,69,70,71];


 /* 
 #define _solve_linear_eqn                    65
 #define _eqns_by_substitution                66
 #define _eqns_by_adding_eqns                 67
 #define _eqns_in_matrix_form                 68
 #define _gauss_jordan                        69
 #define _eqns_by_matrix_inverse              70
 #define _cramers_rule                        71
*/

const SimplifyTopics33 = [72,73,74,75,76,77,78,79,80,81,82,83,84,85,88,99,100,101,102,129,130];

 /* 
 #define _simplify                            72
 #define _simple_commondenom                  73
 #define _advanced_commondenom                74
 #define _compound_fractions                  75
 #define _simplify_polynomials                76
 #define _simple_exponents                    77
 #define _simplify_rational_functions         78
 #define _negative_exponents                  79
 #define _eliminate_negative_exponents        80
 #define _radicals                            81
 #define _absolute_value                      82
 #define _fractional_exponents                83
 #define _eliminate_fractional_exponents      84
 #define _factor_quadratics                   85
 #define _advanced_factoring                  88
 #define _simplify_roots_and_powers           99
 #define _simplify_roots_and_fractions       100
 #define _simplify_any_function              101
 #define _verify_alg2_identity               102
 #define _sigma_notation                     129
 #define _binomial_theorem                   130
*/

const SolveTopics33 = [86,87,89,90,91,92,93,94,95,96,97,98];
/*
 #define _quadratic_formula                   86
 #define _solve_quadratic_equation            87
 #define _solve_higher_degree_equation        89
 #define _solve_rational_equation             90
 #define _solve_root_equation                 91
 #define _solve_fractions_and_roots           92
 #define _solve_linear_inequality             93
 #define _solve_polynomial_inequality         94
 #define _solve_rational_inequality           95
 #define _solve_root_inequality               96
 #define _cubic_one_root                      97
 #define _solve_equation                      98
*/

const TrigTopics33 = [103,104,105,106,107,108,109,110,111,112,113,114];

 /* 
 #define _evaluate_trig                      103
 #define _basic_trig                         104
 #define _trig_addition                      105
 #define _double_angle                       106
 #define _half_angle                         107
 #define _trig_product                       108
 #define _trig_factor                        109
 #define _trig_simplify                      110
 #define _trig_identities                    111
 #define _inverse_trig_functions             112
 #define _simple_trig_eqn                    113
 #define _trig_eqn                           114
*/

const LogExpTopics33 = [116,117,118,119,120,121,124,125]
/*
 #define _logarithms                         116
 #define _change_log_base                    117
 #define _exponentials                       118
 #define _simplify_logpower                  119
 #define _log_eqn                            120
 #define _exp_eqn                            121
 #define _hyperfunctions                     124  // needs to use definitions 
 #define _hyperfunctions2                    125
*/

const ComplexTopics33 = [115,122,123,126,127,128,131];
/*
 #define _complex_arithmetic                 115
 #define _polar_form                         122
 #define _de_moivre                          123
 #define _complex_trig                       126
 #define _complex_quadratics                 127
 #define _complex_cubics                     128
 #define _complex_roots                      131
*/


const DifAndLimitTopics33 = [132,133,134,135,136,137,138,139,140,141,
	142,143,144,145,146,147];

 /* 
 #define _polynomial_limits                  132
 #define _simple_limits                      133
 #define _diff_from_def                      134
 #define _diff_polynomial                    135
 #define _diff_basics                        136
 #define _lim_trig                           137
 #define _diff_trig                          138
 #define _chain_rule                         139
 #define _difreview                          140
 #define _higher_order_diff                  141
 #define _implicit_diff                      142
 #define _related_rates                      143
 #define _minmax                             144
 #define _rational_limits                    145
 #define _limits_at_infinity                 146
 #define _infinite_limits                    147  
*/
	
const ElementaryIntegrationTopics33 = [148,149,150,151,152,153,154];
	
/*
 #define _sigma_notation1                    148
 #define _int_poly                           149
 #define _simple_int                         150
 #define _fundamental_theorem                151
 #define _int_by_substitution                152
 #define _int_by_parts1                      153
 #define _intreview                          154
*/
	
const AdvancedDifferentiationTopics33 = [155,156,157,158,159,160,161,162,163,164,165];

 /* 
 #define _lim_exp                            155
 #define _lhopitals_rule                     156
 #define _limleadingterm                     157
 #define _limits_any_function                158
 #define _diff_exp_from_defn                 159
 #define _diff_exp                           160
 #define _diff_logs                          161
 #define _logarithmic_differentiation        162
 #define _diff_arctrig                       163
 #define _diff_hyperbolic                    164
 #define _diff_any_function                  165
*/
const AdvancedIntegrationTopics33 = [166,167,168,169,170,
	171,172,173];
	
/*	
 #define _int_by_parts2                      166
 #define _int_logs                           167
 #define _trigpower_integrals                168
 #define _trig_substitution                  169
 #define _integrate_rational_functions       170
 #define _rationalizing_substitutions        171
 #define _integrate_any_function             172
 #define _improper_integrals                 173
*/
const InfiniteSeriesTopics33 = [174,175,176,177,178,179];	
/*
 #define _sum_series                         174 // find the sum of a series
 #define _integral_test                      175
 #define _comparison_test                    176
 #define _root_ratio_tests                   177
 #define _power_series1                      178 // beginning power series
 #define _power_series2                      179 // assumes basic series are known
*/

const topics33 = [GraphFunctionTopics33, 
                CalculusGraphTopics33,
	             RelationsAndInequalitiesTopics33,
	             Algebra1Topics33,
	             LinearAlgebraTopics33,
	             SimplifyTopics33,
	             SolveTopics33,
	             TrigTopics33,
	             LogExpTopics33,
	             ComplexTopics33,
	             DifAndLimitTopics33,
	             ElementaryIntegrationTopics33,
	             AdvancedDifferentiationTopics33,
	             AdvancedIntegrationTopics33,
	             InfiniteSeriesTopics33];
	          

var 
topicPicker = null, 
subjectPicker = null, 
problemnumberPicker = null;


function init() 
{
	console.log("init was called");
	var initialSubjectIndex = Number(localStorage.getItem('subjectIndex')) ?? 0;
	var initialTopicIndex = Number(localStorage.getItem('topicIndex')) ?? 0;
	var initialProblemIndex = Number(localStorage.getItem('problemIndex')) ?? 0;
	console.log("initial SubjectIndex = ", initialSubjectIndex);
	console.log("initial TopicIndex = ", initialTopicIndex);
	console.log("initial ProblemIndex = ", initialProblemIndex);
	// This function changes the selectable topics
	function updateTopicSelection() 
	{
		// Check if all pickers are instantiated 
		if(topicPicker != null && subjectPicker != null && problemnumberPicker != null) 
		{
			var subject = subjectPicker.getIndex(),
			problemnumber = problemnumberPicker.getValue();                 
			// Update the value-handler function with the new topics range
			topicPicker.valueHandler = function(index) 
			{
				if(index < 0 || index >= topics33[subject].length) {
				  return null;
				}
				topicIndex = topics33[subject][index];  
				return topics[topicIndex];   
			};
			topicPicker.updateView();
		}
	 }
	function updateProblemnumberSelection() 
	{
		// Check if all pickers are instantiated 
		if (topicPicker != null && subjectPicker != null && problemnumberPicker != null) 
		{
			// Find the problem numbers for the topic.  The problem number is 1 + index.
			var minProblemnumber = 1;
			var subject = subjectPicker.getIndex();
			var topic = topics33[subject][topicPicker.getIndex()];
			var maxProblemnumber =   parseInt(jProblemNumbers[topic-1]);
			// Update the value-handler function with the new problemnumber range
			problemnumberPicker.valueHandler = function (index) 
			{
				// minProblemnumber is always 1,  so index 0 doesn't return null.
				if (index + 1 < minProblemnumber || index+1 > maxProblemnumber) 
					{
						return null;
					}
				return index+1;
			};
			problemnumberPicker.updateView();
		}
	}
	let initializing = true;  // Flag to track if we're still initializing
	// Initialize the subject picker
	subjectPicker = new SpinnerPicker(
				document.getElementById("subject"), 
   			function(index) 
				{
					if(index < 0 || index >= subjects.length)
					{
					 return null;
					}
					return subjects[index];
				}, 
				{ index: initialSubjectIndex },
				function(e) 
					{	if (!initializing) { // Only reset if this is NOT initialization
							if(topicPicker) 
								topicPicker.setIndex(0);
							if(problemnumberPicker) 
								problemnumberPicker.setIndex(0);
							updateTopicSelection(); 
							updateProblemnumberSelection();
						}
					}
          );
			 // Initialize the topic picker
	topicPicker = new SpinnerPicker(   
							document.getElementById("topic"),
							function(index) // 
								{	subject = subjectPicker.getIndex();
									if(index<0|| index >= topics33[subject].length) {
										return null;
									}
									topicIndex = topics33[subject][index];  
									return topics[topicIndex];
								}, 
							{ index: initialTopicIndex },
								function(e) { 
									if (!initializing) { // Only reset if this is NOT initialization
										if(problemnumberPicker) 
											problemnumberPicker.setIndex(0);
										updateProblemnumberSelection();
									}
								}
					);
	var subject, topicIndex, topic;

	// Initialize the problemnumber picker
	problemnumberPicker = new SpinnerPicker(
					document.getElementById("problemnumber"), 
					function(index)  // problem number = index + 1
					{  subject = subjectPicker.getIndex();
						topicIndex = topicPicker.getIndex();
						topic = topics33[subject][topicIndex];
						if(index < 0|| index +1 >   jProblemNumbers[topic])
							{
								return null;
							}
						return (index+1).toString();
					}, 
					{ index: initialProblemIndex },
						function(e) { 
							subject = subjectPicker.getIndex();
							topic = topics33[subject][topicPicker.getIndex()];
							problemSVG = getProblem(topic,e+1);
							document.getElementById("mySVG").innerHTML = problemSVG;
					}
				); 
	// Update views after initialization
	topicPicker.updateView();
	problemnumberPicker.updateView();
	updateTopicSelection();

	// Now that the spinners are set up, show the correct problem
	subject = subjectPicker.getIndex();
	topic = topics33[subject][topicPicker.getIndex()];
	problemSVG = getProblem(topic, problemnumberPicker.getIndex() + 1);
	document.getElementById("mySVG").innerHTML = problemSVG;

	console.log("Finished loading ProblemPicker");

	// **End initialization**
	initializing = false;        
     
}
     

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists