Fancellu commited on
Commit
8505884
·
verified ·
1 Parent(s): 1cf106d

Removed dead code around "reverse", never used

Browse files
Files changed (1) hide show
  1. questionnaire.py +145 -0
questionnaire.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from datetime import datetime
4
+
5
+ # Base 20 questions - balanced across dimensions
6
+ BASE_QUESTIONS = [
7
+ # E/I questions (5 total)
8
+ {"id": 1, "text": "You regularly make new friends.", "dimension": "E"},
9
+ {"id": 2, "text": "You feel comfortable just walking up to someone you find interesting and striking up a conversation.", "dimension": "E"},
10
+ {"id": 3, "text": "At social events, you rarely try to introduce yourself to new people and mostly talk to the ones you already know.", "dimension": "I"},
11
+ {"id": 4, "text": "You prefer to work alone rather than in a team.", "dimension": "I"},
12
+ {"id": 5, "text": "You enjoy participating in group activities.", "dimension": "E"},
13
+
14
+ # S/N questions (5 total)
15
+ {"id": 6, "text": "You are not too interested in discussing various interpretations and analyses of creative works.", "dimension": "S"},
16
+ {"id": 7, "text": "You prefer practical, concrete information over abstract theories.", "dimension": "S"},
17
+ {"id": 8, "text": "You spend a lot of your free time exploring various random topics that pique your interest.", "dimension": "N"},
18
+ {"id": 9, "text": "You like books and movies that make you come up with your own interpretation of the ending.", "dimension": "N"},
19
+ {"id": 10, "text": "You enjoy exploring new ideas and possibilities.", "dimension": "N"},
20
+
21
+ # T/F questions (5 total)
22
+ {"id": 11, "text": "You usually stay calm, even under a lot of pressure.", "dimension": "T"},
23
+ {"id": 12, "text": "You are more inclined to follow your head than your heart.", "dimension": "T"},
24
+ {"id": 13, "text": "Seeing other people cry can easily make you feel like you want to cry too.", "dimension": "F"},
25
+ {"id": 14, "text": "You are very sentimental.", "dimension": "F"},
26
+ {"id": 15, "text": "Your happiness comes more from helping others accomplish things than your own accomplishments.", "dimension": "F"},
27
+
28
+ # J/P questions (5 total)
29
+ {"id": 16, "text": "You often make a backup plan for a backup plan.", "dimension": "J"},
30
+ {"id": 17, "text": "You prefer to completely finish one project before starting another.", "dimension": "J"},
31
+ {"id": 18, "text": "You like to use organizing tools like schedules and lists.", "dimension": "J"},
32
+ {"id": 19, "text": "You usually prefer just doing what you feel like at any given moment instead of planning a particular daily routine.", "dimension": "P"},
33
+ {"id": 20, "text": "You are interested in so many things that you find it difficult to choose what to try next.", "dimension": "P"}
34
+ ]
35
+
36
+ # Additional 20 questions for 40-question version
37
+ EXTENDED_QUESTIONS = [
38
+ # E/I questions (5 more)
39
+ {"id": 21, "text": "You find it easy to stay relaxed and focused even when there is some pressure.", "dimension": "I"},
40
+ {"id": 22, "text": "You are energized by being around other people.", "dimension": "E"},
41
+ {"id": 23, "text": "You prefer to have a few close friends rather than many acquaintances.", "dimension": "I"},
42
+ {"id": 24, "text": "You enjoy being the center of attention.", "dimension": "E"},
43
+ {"id": 25, "text": "You need quiet time to recharge after social activities.", "dimension": "I"},
44
+
45
+ # S/N questions (5 more)
46
+ {"id": 26, "text": "You focus on the here-and-now rather than possibilities for the future.", "dimension": "S"},
47
+ {"id": 27, "text": "You are more interested in what could be than what is.", "dimension": "N"},
48
+ {"id": 28, "text": "You prefer to work with established methods rather than experiment with new approaches.", "dimension": "S"},
49
+ {"id": 29, "text": "You often get so lost in thoughts that you ignore or forget your surroundings.", "dimension": "N"},
50
+ {"id": 30, "text": "You trust experience more than theory.", "dimension": "S"},
51
+
52
+ # T/F questions (5 more)
53
+ {"id": 31, "text": "You consider yourself more practical than creative.", "dimension": "T"},
54
+ {"id": 32, "text": "You find it easy to empathize with a person whose experiences are very different from yours.", "dimension": "F"},
55
+ {"id": 33, "text": "You think that everyone's views should be respected regardless of whether they are supported by facts or not.", "dimension": "F"},
56
+ {"id": 34, "text": "You feel more drawn to places with busy, bustling atmospheres than quiet, intimate places.", "dimension": "T"},
57
+ {"id": 35, "text": "You are more concerned with truth than with people's feelings.", "dimension": "T"},
58
+
59
+ # J/P questions (5 more)
60
+ {"id": 36, "text": "You prefer to improvise rather than spend time coming up with a detailed plan.", "dimension": "P"},
61
+ {"id": 37, "text": "You find deadlines stressful.", "dimension": "P"},
62
+ {"id": 38, "text": "You prefer to have everything planned out in advance.", "dimension": "J"},
63
+ {"id": 39, "text": "You enjoy having a clear routine in your daily life.", "dimension": "J"},
64
+ {"id": 40, "text": "You often leave things to the last minute.", "dimension": "P"}
65
+ ]
66
+
67
+ # Additional 20 questions for 60-question version
68
+ ADVANCED_QUESTIONS = [
69
+ # E/I questions (5 more)
70
+ {"id": 41, "text": "You feel comfortable being spontaneous in social situations.", "dimension": "E"},
71
+ {"id": 42, "text": "You prefer written communication over verbal communication.", "dimension": "I"},
72
+ {"id": 43, "text": "You enjoy networking events and meeting new people.", "dimension": "E"},
73
+ {"id": 44, "text": "You prefer to think things through before speaking.", "dimension": "I"},
74
+ {"id": 45, "text": "You feel energized after attending parties or social gatherings.", "dimension": "E"},
75
+
76
+ # S/N questions (5 more)
77
+ {"id": 46, "text": "You are more interested in the big picture than the details.", "dimension": "N"},
78
+ {"id": 47, "text": "You prefer concrete examples over abstract concepts.", "dimension": "S"},
79
+ {"id": 48, "text": "You enjoy brainstorming and generating new ideas.", "dimension": "N"},
80
+ {"id": 49, "text": "You focus on facts and details rather than interpretations.", "dimension": "S"},
81
+ {"id": 50, "text": "You are drawn to theoretical and philosophical discussions.", "dimension": "N"},
82
+
83
+ # T/F questions (5 more)
84
+ {"id": 51, "text": "You make decisions based on logic rather than feelings.", "dimension": "T"},
85
+ {"id": 52, "text": "You are sensitive to the emotions of others.", "dimension": "F"},
86
+ {"id": 53, "text": "You value harmony and cooperation over competition.", "dimension": "F"},
87
+ {"id": 54, "text": "You prefer objective analysis over personal considerations.", "dimension": "T"},
88
+ {"id": 55, "text": "You find it important to maintain personal relationships even when it's inconvenient.", "dimension": "F"},
89
+
90
+ # J/P questions (5 more)
91
+ {"id": 56, "text": "You like to keep your options open rather than commit to a plan.", "dimension": "P"},
92
+ {"id": 57, "text": "You prefer structure and organization in your work environment.", "dimension": "J"},
93
+ {"id": 58, "text": "You enjoy exploring different possibilities before making a decision.", "dimension": "P"},
94
+ {"id": 59, "text": "You feel satisfied when you complete tasks ahead of schedule.", "dimension": "J"},
95
+ {"id": 60, "text": "You adapt easily to unexpected changes in plans.", "dimension": "P"}
96
+ ]
97
+
98
+ # Question sets
99
+ DEFAULT_QUESTIONS = BASE_QUESTIONS
100
+ FORTY_QUESTIONS = BASE_QUESTIONS + EXTENDED_QUESTIONS
101
+ SIXTY_QUESTIONS = BASE_QUESTIONS + EXTENDED_QUESTIONS + ADVANCED_QUESTIONS
102
+
103
+ def get_questionnaire_by_length(length=20):
104
+ """Get questionnaire by length"""
105
+ if length == 40:
106
+ return FORTY_QUESTIONS
107
+ elif length == 60:
108
+ return SIXTY_QUESTIONS
109
+ else:
110
+ return DEFAULT_QUESTIONS
111
+
112
+ def load_questionnaire(file_path=None, length=20):
113
+ """Load questionnaire from file or return questions by length"""
114
+ if file_path and os.path.exists(file_path):
115
+ with open(file_path, 'r', encoding='utf-8') as f:
116
+ data = json.load(f)
117
+ # If loading from file, use the questions in the file
118
+ if 'questionnaire' in data and 'questions' in data['questionnaire']:
119
+ return data['questionnaire']['questions']
120
+ return data.get('questions', get_questionnaire_by_length(length))
121
+ return get_questionnaire_by_length(length)
122
+
123
+ def save_questionnaire(questionnaire_data, file_path):
124
+ """Save questionnaire data to JSON file"""
125
+ try:
126
+ # Add timestamp
127
+ questionnaire_data['metadata']['saved_at'] = datetime.now().isoformat()
128
+
129
+ # Use temp directory for HF Spaces compatibility
130
+ import tempfile
131
+ temp_dir = tempfile.gettempdir()
132
+ full_path = os.path.join(temp_dir, os.path.basename(file_path))
133
+
134
+ with open(full_path, 'w', encoding='utf-8') as f:
135
+ json.dump(questionnaire_data, f, indent=2, ensure_ascii=False)
136
+ return full_path # Return actual path used
137
+ except Exception as e:
138
+ print(f"Error saving questionnaire: {e}")
139
+ return False
140
+
141
+ if __name__ == "__main__":
142
+ # Test the functions
143
+ questions = load_questionnaire()
144
+ print(f"Loaded {len(questions)} questions")
145
+ print(f"First question: {questions[0]}")