1 Commits
Author SHA1 Message Date
Yasser KB 7dd5fbd84b Finish Project 2023-04-21 13:13:52 +03:00
19 changed files with 209 additions and 133 deletions
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/templates" />
</list>
</option>
</component>
</module>
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/analytics_learning.iml" filepath="$PROJECT_DIR$/.idea/analytics_learning.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
-10
View File
@@ -1,10 +0,0 @@
FROM python
RUN pip install flask scipy matplotlib
# COPY chi_square.py kolmogorov_smirnov.py ./
COPY server.py ./
COPY templates templates
RUN mkdir static
# ENTRYPOINT ["python", "chi_square.py"]
ENTRYPOINT ["flask", "run"]
-8
View File
@@ -1,8 +0,0 @@
run: build
docker compose up
build:
docker compose build
push:
docker compose push
Binary file not shown.
+2 -2
View File
@@ -104,11 +104,11 @@ def index():
plt.savefig('static/plot.png')
# Render template with plot image and results
return render_template('chi_square.html', plot_path='static/plot.png', chisq_stat=chisq_stat, p_value=p_value)
return render_template('home.html', plot_path='static/plot.png', chisq_stat=chisq_stat, p_value=p_value)
else:
# Render initial form
return render_template('chi_square.html')
return render_template('home.html')
if __name__ == '__main__':
app.run(debug=True)
-13
View File
@@ -1,13 +0,0 @@
version: "3.9"
services:
analytics_learning:
image: marcpartensky/analytics_learning
build: .
ports:
- "5000:5000"
environment:
FLASK_APP: server.py
# FLASK_APP: kolmogorov_smirnov.py
# FLASK_APP: chi_square.py
FLASK_RUN_HOST: "0.0.0.0"
FLASK_RUN_PORT: 5000
+4 -4
View File
@@ -103,11 +103,11 @@ def index():
plt.savefig('static/plot.png')
# Render template with plot
return render_template('kolmogorov_smirnov.html', plot_url='static/plot.png')
return render_template('index.html', plot_url='static/plot.png')
else:
return render_template('kolmogorov_smirnov.html', error=True)
return render_template('index.html', error=True)
else:
return render_template('kolmogorov_smirnov.html')
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True, port=8000)
-95
View File
@@ -1,95 +0,0 @@
#!/usr/bin/env python
from flask import Flask, render_template, request
import numpy as np
import scipy.stats as stats
from scipy.stats import expon, gamma, norm, poisson
import matplotlib.pyplot as plt
app = Flask(__name__)
# Define routes
@app.route('/chi_square', methods=['GET', 'POST'])
def chi_square():
if request.method == 'POST':
# Get distribution type from form submission
distribution_type = request.form['distribution_type']
# Generate random sample data for selected distribution
if distribution_type == 'normal':
data = np.random.normal(loc=0, scale=1, size=100)
elif distribution_type == 'exponential':
data = np.random.exponential(scale=1, size=100)
elif distribution_type == 'poisson':
data = np.random.poisson(lam=1, size=100)
elif distribution_type == 'gamma':
data = np.random.gamma(shape=2, scale=1, size=100)
# Calculate expected values for selected distribution
if distribution_type == 'normal':
expected = stats.norm(loc=np.mean(data), scale=np.std(data)).pdf(data)
elif distribution_type == 'exponential':
expected = stats.expon(scale=np.mean(data)).pdf(data)
elif distribution_type == 'poisson':
expected = stats.poisson(mu=np.mean(data)).pmf(data)
elif distribution_type == 'gamma':
expected = stats.gamma(a=np.mean(data)**2/np.var(data), scale=np.var(data)/np.mean(data)).pdf(data)
# Calculate Chi-square statistic and p-value
chisq_stat, p_value = stats.chisquare(f_obs=np.histogram(data, bins='auto')[0], f_exp=expected)
# Create histogram of sample data and plot expected distribution
plt.hist(data, bins='auto', density=True, alpha=0.7)
plt.plot(data, expected, 'r-', lw=2)
plt.title(f'{distribution_type.capitalize()} Distribution')
plt.xlabel('Value')
plt.ylabel('Density')
plt.savefig('static/plot.png')
# Render template with plot image and results
return render_template('chi_square.html', plot_path='static/plot.png', chisq_stat=chisq_stat, p_value=p_value)
else:
# Render initial form
return render_template('chi_square.html')
@app.route('/kolmogorov_smirnov', methods=['GET', 'POST'])
def kolmogorov_smirnov():
if request.method == 'POST':
# Get user input
distribution_type = request.form['distribution_type']
num_samples = int(request.form['num_samples'])
# Generate data
if distribution_type == 'normal':
data = norm.rvs(size=num_samples)
elif distribution_type == 'uniform':
data = np.random.uniform(size=num_samples)
elif distribution_type == 'standard':
data = np.random.randn(num_samples)
elif distribution_type == 'exponential':
data = expon.rvs(size=num_samples)
elif distribution_type == 'poisson':
data = poisson.rvs(mu=5, size=num_samples)
elif distribution_type == 'gamma':
data = gamma.rvs(a=5, size=num_samples)
else:
data = None
# Generate plot
if data is not None:
plt.hist(data, bins=30)
plt.title(f'{distribution_type.capitalize()} Distribution')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.savefig('static/plot.png')
# Render template with plot
return render_template('kolmogorov_smirnov.html', plot_url='static/plot.png')
else:
return render_template('kolmogorov_smirnov.html', error=True)
else:
return render_template('kolmogorov_smirnov.html')
if __name__ == '__main__':
app.run(debug=True)
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+92
View File
@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html>
<head>
<title>Statistical Analysis Application</title>
<style>
/* styles pour les boutons */
.btn {
display: inline-block;
padding: 12px 24px;
font-size: 16px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #fff;
background-color: #007bff;
border-radius: 4px;
transition: all 0.3s ease;
}
.btnn {
display: inline-block;
padding: 12px 24px;
font-size: 16px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #fff;
background-color: #007bff;
border-radius: 4px;
transition: all 0.3s ease;
}
.btnn:hover {
background-color: #0062cc;
}
/* styles pour le formulaire */
form {
max-width: 600px;
margin: 0 auto;
padding: 24px;
border: 1px solid #ddd;
border-radius: 4px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 8px;
font-size: 16px;
font-weight: bold;
}
input[type="text"] {
width: 100%;
padding: 12px;
border-radius: 4px;
border: 1px solid #ddd;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Statistical Analysis Application</h1>
<form action="/result" method="post">
<label for="test_statistique">Statistical Test</label>
<select name="test_statistique" id="test_statistique">
<option value="distribution">Distribution fitting</option>
<option value="t_test">Two-sample problem</option>
<option value="correlation_regression">Correlation/Regression</option>
<option value="classification">Classification</option>
</select>
<label for="sample_size">Sample size</label>
<input type="text" name="sample_size" id="sample_size" placeholder="Entrez la taille de l'échantillon">
<label for="group_size">Group size (for two-sample tests)</label>
<input type="text" name="group_size" id="group_size" placeholder="Entrez la taille du groupe">
<label for="significance">Meaning of results</label>
<select name="significance" id="significance">
<option value="significant">Statistically significant</option>
<option value="non_significant">Statistically not significant</option>
<option value="both">Both results</option>
</select>
</form>
<a href="http://127.0.0.1:8000">
<button type="submit" class="btnn">Analyze Data</button>
</a>
</body>
</html>
@@ -4,7 +4,7 @@
<title>Plotting Distributions with Flask</title>
</head>
<body>
<h1>Plotting Distributions with Flask</h1>
<h1>Plotting Distributions</h1>
{% if error %}
<p style="color:red;">Invalid distribution type selected</p>
{% endif %}
+28
View File
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Résultats de l'analyse statistique</title>
</head>
<body>
<h1>Résultats de l'analyse statistique</h1>
<p>Voici les résultats de l'analyse statistique :</p>
<table>
<tr>
<th>Test statistique</th>
<td>{{ test_statistique }}</td>
</tr>
<tr>
<th>Paramètres du test</th>
<td>{{ parametres }}</td>
</tr>
<tr>
<th>Résultat</th>
<td>{{ resultat }}</td>
</tr>
<tr>
<th>Conclusion</th>
<td>{{ conclusion }}</td>
</tr>
</table>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
from flask import Flask, render_template, request
app = Flask(__name__)
# Définir la page d'accueil
@app.route('/')
def home():
return render_template('hm.html')
# Définir la page des résultats
@app.route('/results', methods=['POST'])
def results():
# Récupérer les données entrées par l'utilisateur
test = request.form['test']
sample_size = request.form['sample_size']
group_size = request.form['group_size']
outcome_variable = request.form['outcome_variable']
significance = request.form['significance']
# Appeler les fonctions appropriées pour effectuer les calculs et les tests statistiques
# En fonction des données entrées par l'utilisateur
# Renvoyer les résultats à la page des résultats
return render_template('rs.html', test=test, sample_size=sample_size, group_size=group_size,
outcome_variable=outcome_variable, significance=significance)
if __name__ == '__main__':
app.run(debug=True)