Skip to content

Commit

Permalink
Refactor category handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed May 28, 2024
1 parent ebeb6ad commit 36307f9
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 40 deletions.
27 changes: 3 additions & 24 deletions frontend/src/components/ResultPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { ref, computed, watchEffect } from 'vue'
import { ref, computed } from 'vue'
import axios from 'axios'
import SnackbarAlert from '@/components/SnackbarAlert.vue'
import { TYPOLOGIES, MEASURED_GUNS_TYPOLOGIES } from '@/utils/firearms-utils/index'
Expand All @@ -13,32 +13,11 @@ import { getMentionsFromCategories } from '@/utils/mentions'
const { setMessage } = useSnackbarStore()
const stepsStore = useStepsStore()
const resultStore = useResultStore()
const router = useRouter()
const route = useRoute()
function getCategoryFromTypologyAndMeasures (typology: string, gunLength: number, gunBarrelLength: number) {
if (gunLength !== null && gunBarrelLength !== null) {
switch (typology) {
case 'epaule_a_pompe':
if (gunLength > 75 && gunBarrelLength > 55) { return 'C' } else { return 'B' }
case 'epaule_a_un_coup_par_canon':
if (gunLength > 75 && gunBarrelLength > 40) { return 'C' } else { return 'B' }
case 'epaule_a_levier_sous_garde': case 'epaule_a_verrou': case 'epaule_semi_auto_style_chasse':
if (gunLength < 75 || gunBarrelLength < 40) { return 'B' }
if (gunLength > 75 && gunBarrelLength > 55) { return 'C' }
}
}
return TYPOLOGIES[typology]?.category
}
watchEffect(() => {
if (!resultStore.img) router.push({ name: 'StartPage' })
})
const confidence = computed(() => resultStore.confidence)
const confidenceLevel = computed(() => resultStore.confidenceLevel)
const img = computed(() => resultStore.img)
const imgUrl = computed(() => resultStore.imgUrl)
const typology = computed(() => resultStore.typology)
Expand All @@ -60,15 +39,15 @@ const category = computed(() => {
} else if (typology.value === 'revolver') {
return TYPOLOGIES[typology.value]?.categoryWithoutSecuring
} else {
return getCategoryFromTypologyAndMeasures(typology.value, resultStore.gunLength, resultStore.gunBarrelLength)
return TYPOLOGIES[typology.value]?.getCategory(resultStore.gunLength, resultStore.gunBarrelLength)
}
})
const disclaimer = computed(() => TYPOLOGIES[typology.value] && Object.hasOwn(TYPOLOGIES[typology.value], 'getDisclaimer') ? TYPOLOGIES[typology.value].getDisclaimer(category.value, isCardDetected.value) : null)
function sendFeedback (isCorrect: boolean) {
const json = {
image_url: imgUrl.value,
image_url: resultStore.imgUrl,
feedback: isCorrect,
confidence: confidence.value,
label: typology.value,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/firearms-utils/arme-alarme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import pistoletAlarmeImg13Zoom from '@/assets/guide-identification/photos/arme_a

export const arme_alarme = {
displayLabel: 'Arme d\'alarme',
category: 'D',
getCategory: () => 'D',
options: [
{
label: 'ZORAKI R2',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/firearms-utils/autre-pistolet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Autre pistolet
export const autre_pistolet = {
typologie: 'autre_pistolet',
displayLabel: 'Pistolet divers',
category: 'A, B ou D',
getCategory: () => 'A, B ou D',
isDummyTypology: false,
options_text: '',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import levierSousGardeMagasinAvantImg from '@/assets/guide-mise-en-securite/phot
import levierSousGardePasMagasinImg from '@/assets/guide-mise-en-securite/photos/epaule_a_levier_sous_garde/epaule_levier_ss_garde_magasin_fixe.jpg'
import levierSousGardeMagasinAvantVideo from '@/assets/guide-mise-en-securite/videos/epaule_a_levier_sous_garde/epaule_levier_ss_garde_magasin_avant.mp4'
import levierSousGardePasMagasinVideo from '@/assets/guide-mise-en-securite/videos/epaule_a_levier_sous_garde/epaule_levier_ss_garde_magasin_fixe.mp4'
import { getEpaulLevierVerrouDisclaimer } from '@/utils/firearms-utils/index'
import { getEpaulLevierVerrouDisclaimer, getCommonCategory } from '@/utils/firearms-utils/index'
/*
Armes d’épaule à levier de sous-garde
Magasin avant
Magasin fixe
*/
export const epaule_a_levier_sous_garde = {
displayLabel: "Arme d'épaule à levier de sous-garde",
category: 'B ou C',
getCategory: getCommonCategory,
isDummyTypology: false,
options_text: 'En manipulant l’arme avec précaution dans une <span class="font-bold">direction sans risque</span>, inspectez l’<span class="font-bold">extrémité du tube sous le canon</span>. Sélectionnez ce que vous voyez :',
options: {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/utils/firearms-utils/epaule-a-pompe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import epaulePompeSimpleVideo from '@/assets/guide-mise-en-securite/videos/epaul
// import epaulePompeCompliqueVideo from '@/assets/guide-mise-en-securite/videos/epaule_a_pompe/epaule_pompe_complique.mp4'
/*
3 - Armes d’épaule à pompe
*/
export const epaule_a_pompe = {
displayLabel: "Arme d'épaule à pompe",
category: 'B ou C',
getCategory: (gunLength: number, gunBarrelLength: number) => {
if (gunLength && gunBarrelLength) { return gunLength > 75 && gunBarrelLength > 55 ? 'C' : 'B' } else { return 'B ou C' }
},
isDummyTypology: false,
options_text: '',
text_steps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Armes d’épaule à un coup par canon
*/
export const epaule_a_un_coup_par_canon = {
displayLabel: "Arme d'épaule à un coup par canon",
category: 'B ou C',
getCategory: (gunLength: number, gunBarrelLength: number) => {
if (gunLength && gunBarrelLength) { return (gunLength > 75 && gunBarrelLength > 40) ? 'C' : 'B' } else { return 'B ou C' }
},
isDummyTypology: false,
options_text: 'Sélectionnez ce que vous voyez sur la <span class="font-bold">zone centrale de l’arme</span>',
options: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/firearms-utils/epaule-a-verrou.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import epauleAVerrouCartridges from '@/assets/guide-identification/photos/epaule_a_verrou/epaule_a_verrou_chargeur_cartouche.jpg'
import epauleAVerrouBalls from '@/assets/guide-identification/photos/epaule_a_verrou/epaule_a_verrou_chargeur_bille.jpg'
import epauleAVerrouVideo from '@/assets/guide-mise-en-securite/videos/epaule_a_verrou/epaule_verrou_chargeur-video.mp4'
import { getEpaulLevierVerrouDisclaimer } from '@/utils/firearms-utils/index'
import { getEpaulLevierVerrouDisclaimer, getCommonCategory } from '@/utils/firearms-utils/index'

/*
Armes d’épaule à verrou
*/
export const epaule_a_verrou = {
displayLabel: 'Arme d’épaule à verrou',
category: 'B ou C',
getCategory: getCommonCategory,
isDummyTypology: true,
text_steps: {
1: 'Observer l’arme en l’orientant dans une <span class="font-bold">direction sans risque</span>, en manipulant avec précaution',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Armes d’épaule semi-automatiques ou automatiques type militaire milieu 20e
*/
export const epaule_semi_auto_style_militaire_milieu_20e = {
displayLabel: 'Arme d’épaule semi-automatique ou automatique',
category: 'A ou B',
getCategory: () => 'A ou B',
isDummyTypology: false,
getDisclaimer: () => "<strong>Catégorie A</strong> si à l'origine l’arme était à <strong>répétition automatique</strong> puis a été <strong>transformée</strong> en arme <strong>semi automatique</strong>, ou si l’arme possède <strong>une crosse rétractable / pliable</strong> et qu’en configuration la plus courte elle <strong>mesure moins de 60 cm</strong>.",
} as const
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getCommonCategory } from '@/utils/firearms-utils/index'

const DISCLAIMERS = {
short: '<strong>Catégorie B</strong> si la <strong>capacité > à 3 munitions</strong>, ou si le <strong>chargeur est amovible</strong>.',
long: '<ul><li><strong>Catégorie B</strong> si la <strong>capacité > à 3 munitions</strong>, ou si le <strong>canon est lisse</strong>, ou si le <strong>chargeur est amovible</strong>.</li><li><strong>Catégorie C</strong> si le <strong>canon est rayé</strong>.</li></ul>',
Expand All @@ -8,7 +10,7 @@ Armes d’épaule semi-automatiques ou automatiques type chasse
*/
export const epaule_semi_auto_style_chasse = {
displayLabel: 'Arme d’épaule semi-automatique',
category: 'B ou C',
getCategory: getCommonCategory,
isDummyTypology: false,
getDisclaimer: (category: string, isCardDetected: boolean) => {
if (['B ou C', 'C'].includes(category)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Armes d’épaule à mécanisme ancien
*/
export const epaule_mecanisme_ancien = {
displayLabel: "Arme d'épaule à mécanisme ancien",
category: 'D',
getCategory: () => 'D',
isDummyTypology: false,
} as const
8 changes: 8 additions & 0 deletions frontend/src/utils/firearms-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,11 @@ export function getEpaulLevierVerrouDisclaimer (category: string, isCardDetected
return '<ul><li><strong>Catégorie B</strong> : si la capacité > 11 munitions ou si le <strong>canon est lisse</strong></li><li><strong>Catégorie C</strong> : si la capacité < 11 munitions et le <strong>canon est rayé</strong></li></ul>'
}
}

export function getCommonCategory (gunLength: number, gunBarrelLength: number) {
if (gunLength && gunBarrelLength) {
if (gunLength < 75 || gunBarrelLength < 40) { return 'B' }
if (gunLength > 75 && gunBarrelLength > 55) { return 'C' }
}
return 'B ou C'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Pistolet à mécanisme ancien
*/
export const pistolet_mecanisme_ancien = {
displayLabel: 'Pistolet à mécanisme ancien',
category: 'D',
getCategory: () => 'D',
isDummyTypology: false,
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pistolets semi-auto modernes
*/
export const pistolet_semi_auto_moderne = {
displayLabel: 'Pistolet semi-automatique',
category: 'B',
getCategory: () => 'B',
isDummyTypology: true,
pistolet_semi_auto_moderne_text_option: 'Sélectionner ce que vous voyez sur votre arme : <span class="font-bold">bouton à proximité du pontet du côté gauche de la poignée</span>, OU <span class="font-bold">bouton sur le talon</span> de la crosse.',
textOptions: '',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/firearms-utils/revolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Revolvers
*/
export const revolver = {
displayLabel: 'Revolver',
category: 'B',
getCategory: () => 'B',
categoryWithoutSecuring: 'B ou D',
isDummyTypology: true,
options_step_1_text: 'En maintenant l’arme dans une <span class="font-bold">direction sécurisée</span> , sélectionnez ce que vous voyez.',
Expand Down Expand Up @@ -223,6 +223,6 @@ export const revolver = {

export const revolver_black_powder = {
displayLabel: 'Revolver à poudre noire',
category: 'D',
getCategory: () => 'D',
isDummyTypology: false,
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Armes d’épaule semi-automatiques ou automatiques type militaire moderne
*/
export const semi_auto_style_militaire_autre = {
displayLabel: 'Arme semi-automatique ou automatique',
category: 'A ou B',
getCategory: () => 'A ou B',
isDummyTypology: true,
options_text: 'Observez la position du chargeur et sélectionnez ce que vous voyez :',
options: {
Expand Down

0 comments on commit 36307f9

Please sign in to comment.