Coder Social home page Coder Social logo

Comments (5)

ArtemijRodionov avatar ArtemijRodionov commented on June 20, 2024

I have used this code to assume units for tags:

from collections import Counter
from itertools import chain
from stroyprombeton import models as stb_models

def most_common(group):
    return Counter(chain.from_iterable(
            t.name.split(' ') for t in group.tags.all()
        )).most_common(10)
for g in stb_models.TagGroup.objects.all():
    print(g.name, ':', most_common(g))

The result:

Длина : [('м', 760), ('279', 2), ('4600', 2), ('1860', 2), ('3360', 2), ('2760', 2), ('2160', 2), ('3000', 2), ('4000', 2), ('5280', 2)]
Ширина : [('м', 403), ('750', 2), ('900', 2), ('1100', 2), ('1000', 2), ('1200', 2), ('2100', 2), ('2500', 2), ('1500', 2), ('2000', 2)]
Высота : [('м', 439), ('750', 2), ('900', 2), ('1100', 2), ('200', 2), ('250', 2), ('300', 2), ('350', 2), ('400', 2), ('580', 2)]
Масса : [('кг', 1465), ('2330.0', 2), ('5280.0', 2), ('480.0', 2), ('900.0', 2), ('5300.0', 2), ('6300.0', 2), ('350.0', 2), ('470.0', 2), ('700.0', 2)]
Объём : [('м', 946), ('куб', 946), ('0.97', 2), ('1.4', 2), ('2.2', 2), ('0.2', 2), ('0.35', 2), ('1.3', 2), ('2.52', 2), ('0.13', 2)]
Внешний диаметр : [('м', 43), ('660', 2), ('910', 2), ('1200', 2), ('1240', 2), ('1530', 2), ('1780', 2), ('1820', 2), ('1940', 2), ('2400', 2)]
Внутренний диаметр : [('м', 17), ('500', 2), ('750', 2), ('1000', 2), ('1250', 2), ('1500', 2), ('2000', 2), ('400', 1), ('700', 1), ('2500', 1)]
Рабочая документация : [('Серия', 42), ('выпуск', 28), ('3.900.1-10,', 8), ('1.152.1-8,', 7), ('1', 6), ('3.006.1-3/83,', 3), ('2', 3), ('3.902.1-12,', 3), ('3', 2), ('6', 2)]

This is group of tags to unit map:

Длина, Высота, Ширина, Внешний диаметр, Внутренний диаметр -> м
Масса -> кг
Объём -> м куб

from stroyprombeton.

ArtemijRodionov avatar ArtemijRodionov commented on June 20, 2024

Done

from stroyprombeton.

ArtemijRodionov avatar ArtemijRodionov commented on June 20, 2024

I have used this script:

from django.db.utils import IntegrityError
from stroyprombeton import models as stb_models

def add_units_to_tags():
    m = 'м'
    units = {
        'Длина': m,
        'Высота': m,
        'Ширина': m,
        'Внешний диаметр': m,
        'Внутренний диаметр': m,
        'Масса': 'кг',
    }
    duplicates = []
    complex_units = {'Объём': 'м куб'}
    for tag in stb_models.Tag.objects.all():
        group_name = tag.group.name
        if group_name not in units and group_name not in complex_units:
            print(f'Skip {group_name}')
            continue
        if group_name in units and units[group_name] not in tag.name.split(' '):
            units_to_set = units[group_name]
        elif group_name in complex_units and len(tag.name.split(complex_units[group_name])) == 1:
            units_to_set = complex_units[group_name]
        else:
            units_to_set = ''
        tag.name = f'{tag.name} {units_to_set}'.strip()
        try:
            tag.save()
        except IntegrityError:
            duplicates.append({
                'dup_id': tag.id,
                'orig': {
                    'name': tag.name,
                    'group_id': tag.group.id}})
    return duplicates

from stroyprombeton.

duker33 avatar duker33 commented on June 20, 2024

@artemiy312 , it seems we should have мм instead of м for metrical dimensions.
That's pretty what is #746 what about. Assigned it on you

from stroyprombeton.

ArtemijRodionov avatar ArtemijRodionov commented on June 20, 2024

I have added units for 49 tags. The rest of 1577 have been removed in this issue #754 as duplicates

from stroyprombeton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.