R
R
redduckrobot2016-07-12 21:38:03
Django
redduckrobot, 2016-07-12 21:38:03

Is it worth using a graph and in what cases are they used?

Hello. I faced the following problem: there is a division of users into men and women, for men there is immediately a breakdown by age with data binding, and for women, first it goes by pregnant / lactating / normal and then by age with data:

data: женщина, беременная, 18-30, набор_данных1
data: женщина, нормальная, 18-30, набор_данных2
data: мужчина, 15-18, набор_данных3

data2:...

First, I attached additional fields to data with gender, status (for women), age, and data. It is decided not forcibly through ifs, but now I thought about what this tree is and wouldn’t it be easier to pull out the necessary data in another way? Unfortunately, I didn’t have time to get acquainted with the graphs in detail, so I ask for your hints whether it is worth doing it this way, or differently, or maybe leave it as it is, and how to generally determine when a graph is needed (in this case, a tree).
So, what if you bind a textfield to data and write data to it in the dictionary / json / etc format and access it by keys? Those.
a = {
   'female': {
      'pregnant': {'18-30': 'data_set'},
      ...
   },
   'male': {'15-18': 'data_set2'}
}

Well, then, to get the data, we take the user’s data and supply the keys:
user_data = a[gender][status][age_range]
though there are two problems here, this is the lack of a man’s status and you need to add a little code to get exactly the data by age_range, but that’s not scary.
What do you think?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
sim3x, 2016-07-12
@sim3x

For analytics - it's better to stay in sql
For ease of writing - also
If you want to suffer and pull an owl on the globe - use graph databases

Z
zelsky, 2016-07-12
@zelsky

If I understand the question, then do everything too, but on a NoSQL basis. For example mongo. Everything is in json if I understand nosql correctly

A
Alexey Cheremisin, 2016-07-12
@leahch

Oh, how well your data fit on elasticsearch!

A
AtomKrieg, 2016-07-13
@AtomKrieg

You missed the section on data structures in python. Graphs are not for such tasks. In your case, you need:
collection = defaultdict(list)
key = ("male", "18-25")
data = ...
collection[key].append(data)
Well, continue to twist this data structure
Graphs for finding paths. There is almost no application for business tasks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question