From b608879b88750806890e7f8bf77e8cdb431a69dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Mart=C3=ADnez?= Date: Tue, 1 Oct 2024 20:02:54 +0200 Subject: [PATCH] Delete ununsed files --- server/api/house/list.get.ts | 13 --- server/api/house/parse.get.ts | 12 --- server/db/mysql/models/Property.js | 64 ----------- server/services/fusejs/filterProperties.js | 100 ------------------ .../fuzzySearch/fuzzySearchService.ts | 66 ------------ 5 files changed, 255 deletions(-) delete mode 100644 server/api/house/list.get.ts delete mode 100644 server/api/house/parse.get.ts delete mode 100644 server/db/mysql/models/Property.js delete mode 100644 server/services/fusejs/filterProperties.js delete mode 100644 server/services/fuzzySearch/fuzzySearchService.ts diff --git a/server/api/house/list.get.ts b/server/api/house/list.get.ts deleted file mode 100644 index 655a32e..0000000 --- a/server/api/house/list.get.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Property } from "../../db/mysql/db.config"; -import { groupSimilarProperties } from "../../services/fusejs/filterProperties"; - -export default defineEventHandler(async (event) => { - try { - const candidateProperties = await Property.findAll(); - const properties = groupSimilarProperties(candidateProperties); - return { success: true, properties }; - } catch (error) { - console.error("Error listing properties:", error); - return { success: false, message: error.message }; - } -}); diff --git a/server/api/house/parse.get.ts b/server/api/house/parse.get.ts deleted file mode 100644 index 0eefcf1..0000000 --- a/server/api/house/parse.get.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Property } from "../../db/mysql/db.config"; - -export default defineEventHandler(async (event) => { - try { - const body = await readBody(event); - const newProperty = await Property.create(body); - return { success: true, property: newProperty }; - } catch (error) { - console.error("Error creating property:", error); - return { success: false, message: error.message }; - } -}); diff --git a/server/db/mysql/models/Property.js b/server/db/mysql/models/Property.js deleted file mode 100644 index 9e445d3..0000000 --- a/server/db/mysql/models/Property.js +++ /dev/null @@ -1,64 +0,0 @@ -// server/models/Property.js -import { DataTypes } from "sequelize"; - -export default function Property (sequelize) { - return sequelize.define( - "Property", - { - id: { - type: DataTypes.STRING, - allowNull: true, - unique: true, - primaryKey: true, - }, - title: { - type: DataTypes.STRING, - allowNull: true, - }, - url: { - type: DataTypes.STRING, - allowNull: true, - }, - price: { - type: DataTypes.STRING, - allowNull: true, - }, - rooms: { - type: DataTypes.INTEGER, - allowNull: true, - }, - area: { - type: DataTypes.INTEGER, - allowNull: true, - }, - level: { - type: DataTypes.STRING, - allowNull: true, - }, - description: { - type: DataTypes.TEXT, - allowNull: true, - }, - pic: { - type: DataTypes.TEXT, - allowNull: true, - }, - baths: { - type: DataTypes.INTEGER, - allowNull: true, - }, - neighborhood: { - type: DataTypes.STRING, - allowNull: true, - }, - phone: { - type: DataTypes.STRING, - allowNull: true, - }, - }, - { - tableName: "properties", - timestamps: true, // Incluye createdAt y updatedAt - } - ); -}; \ No newline at end of file diff --git a/server/services/fusejs/filterProperties.js b/server/services/fusejs/filterProperties.js deleted file mode 100644 index 9754629..0000000 --- a/server/services/fusejs/filterProperties.js +++ /dev/null @@ -1,100 +0,0 @@ -// utils/filterProperties.js -import Fuse from 'fuse.js'; - -export const filterSimilarProperties = (properties) => { - const options = { - keys: ['_title'], // Solo buscamos similitud en el título - threshold: 0.55, // 0.6 es un umbral para 40% de similitud - includeScore: true // Incluye la puntuación de similitud - }; - - const fuse = new Fuse(properties, options); - const uniqueProperties = []; - const seen = new Set(); // Usaremos un conjunto para rastrear propiedades vistas - - properties.forEach((property) => { - const propertyData = property; - if (!seen.has(propertyData._id)) { - // Inicializa el array para IDs similares en dataValues - propertyData.similarIds = []; - - // Buscamos propiedades similares por título - const result = fuse.search(propertyData._title).filter((res) => { - const similarProperty = res.item; - // Filtramos resultados que no sean la misma propiedad y sean similares en título - const isSimilar = res.item._id !== propertyData._id && res.score < options.threshold; - - if (isSimilar) { - propertyData.similarIds.push(similarProperty._id); - - // Enriquecer la propiedad actual con datos de la propiedad similar - // propertyData.title = getLongest(propertyData.title, similarProperty.title); - // propertyData.url = propertyData.url || similarProperty.url; - // propertyData.price = propertyData.price || similarProperty.price; - // propertyData.rooms = propertyData.rooms || similarProperty.rooms; - // propertyData.area = propertyData.area || similarProperty.area; - // propertyData.level = propertyData.level || similarProperty.level; - // propertyData.description = getLongest(propertyData.description, similarProperty.description); - // propertyData.pic = propertyData.pic || similarProperty.pic; - // propertyData.baths = propertyData.baths || similarProperty.baths; - // propertyData.neighborhood = propertyData.neighborhood || similarProperty.neighborhood; - // propertyData.phone = propertyData.phone || similarProperty.phone; - - // Marcar la propiedad similar como vista - //seen.add(similarProperty.id); - } - - return isSimilar; - }); - - uniqueProperties.push(property); - } - }); - - return uniqueProperties; -}; - -export const groupSimilarProperties = (properties) => { - const filteredProperties = filterSimilarProperties(properties); - const groups = []; - const visited = new Set(); - - filteredProperties.forEach((property) => { - const propertyId = property._id; - if (!visited.has(propertyId)) { - const group = [property]; - visited.add(propertyId); - - const queue = [...property.similarIds]; - while (queue.length > 0) { - const currentId = queue.shift(); - if (!visited.has(currentId)) { - const similarProperty = filteredProperties.find(prop => prop._id === currentId); - if (similarProperty) { - group.push(similarProperty); - visited.add(currentId); - queue.push(...similarProperty.similarIds.filter(id => !visited.has(id))); - } - } - } - - groups.push(group); - } - }); - - // Convert groups to desired output format - const groupedProperties = groups.reduce((acc, group, index) => { - acc[index] = group; - return acc; - }, {}); - - return groupedProperties; -}; - - - -const getLongest = (a, b) => { - if (!a) return b; - if (!b) return a; - return a.length >= b.length ? a : b; -}; \ No newline at end of file diff --git a/server/services/fuzzySearch/fuzzySearchService.ts b/server/services/fuzzySearch/fuzzySearchService.ts deleted file mode 100644 index 78c1532..0000000 --- a/server/services/fuzzySearch/fuzzySearchService.ts +++ /dev/null @@ -1,66 +0,0 @@ -import stringSimilarity from 'string-similarity'; - -export class FuzzySearchService { - _data: any = []; - _threshold: number; - - private constructor(data, threshold) { - this._data = data; - this._threshold = threshold; - } - - public static create(data, threshold = 0.7) { - return new FuzzySearchService(data, threshold); - } - - matchSimilarProperty(property) { - const groupedData: Map = new Map(); - - this.data.forEach((obj) => { - let found = false; - - for (const [key, group] of groupedData.entries()) { - const representativeObj: any = group[0]; - - if ( - this.isPropertySimilar(representativeObj[property], obj[property]) - ) { - group.push(obj); - groupedData.set(key, group); - found = true; - break; - } - } - - if (!found) { - // Crea una nueva clave en el mapa para un nuevo grupo - groupedData.set(obj.id, [obj]); - } - }); - - return groupedData; - } - - matchExactProperty(property) { - // Implement your exact property matching logic here - // Return the matched property - } - - matchExactProperties(properties) { - // Implement your exact properties matching logic here - // Return the matched properties - } - - isPropertySimilar(property, otherProperty: string): boolean { - const similarity = stringSimilarity.compareTwoStrings(property, otherProperty); - return similarity >= this.threshold; - } - - get data() { - return this._data; - } - - get threshold() { - return this._threshold; - } -} \ No newline at end of file