Giter Club home page Giter Club logo

django-dag's Introduction

Django DAG
----------

Django-dag is a small reusable app which implements a Directed Acyclic Graph.

Usage
.....

Django-dag uses abstract base classes, to use it you must create your own
concrete classes that inherit from Django-dag classes.

The `dag_test` app contains a simple example and a unit test to show
you its usage.

Example::

    class ConcreteNode(node_factory('ConcreteEdge')):
        """
        Test node, adds just one field
        """
        name = models.CharField(max_length = 32)

    class ConcreteEdge(edge_factory(ConcreteNode, concrete = False)):
        """
        Test edge, adds just one field
        """
        name = models.CharField(max_length = 32, blank = True, null = True)


Tests
.....

Unit tests can be run with just django installed at the base directory by running
   `python manage.py test`

django-dag's People

Contributors

elpaso avatar eyu-boltthreads avatar farahzadi avatar frederik-elwert avatar ghing avatar hackaugusto avatar iiseymour avatar rgammans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-dag's Issues

Licensing change?

I would like to use this software in a commercial application but I can not because "Thus the GNU Affero GPL v3 stipulates that any adaptation of software that it covers must prominently offer its source code for download to users who interact with it over a network."

http://oss-watch.ac.uk/resources/agpl

Can you change the license to something less restrictive?

Problems with migrations in Django 1.11

I'm developing a package with Django 1.11 which depends on django-dag.

There are 2 models in the app depending on dag:

class BayesianNetworkEdge(
        edge_factory('bayesian_networks.BayesianNetworkNode')):
        ....

class BayesianNetworkNode(
        node_factory('bayesian_networks.BayesianNetworkEdge')):
        ....

The problem is that on a fresh install, django_dag does not ships with the initial migration and Django creates it when another migration requiring it is created.

If I ship that migration (pointing to django_dag tables) it will fail on a fresh install because it points to a non-existent one, and the migrations have to be deleted and recreated to trigger the creation of dag tables.

Have you consider including an initial migration with those tables in order to fix this kind of problems?

Push1.4 to Pypi

Thanks for merging my requests, do you think you could push the latest version to pypi?

query optimization

This isn't a bug or problem per se- but while doing some query optimizations in my project, I realized that the descendants_tree() (and I assume ancestor_tree and ans_set/des_set) command(s) uses a large number of queries to complete. I'm wondering if there is an easy way to cut down the number of queries for the nested structure. I had something in mind like a select_related() query that could at least cut down the number of db hits.
For now, the rest of my project is too important to overlook, so it may be a while until I can get back to it and work on a pull request.
Thanks for this project!

Unique together constraint on ('child_id','parent_id') ?

Are duplicate child_id/parent_id pairs valid? Or should we apply a unique constraint to avoid adding the same child to the same parent more than once, as shown below:

bdipr=# select * from django_dag_edge;
 id | child_id | parent_id 
----+----------+-----------
  1 |        1 |         2
  2 |        1 |         2
(2 rows)

TypeError: save() got an unexpected keyword argument 'disable_circular_check' [migrations]

(ENV) rodrigo@enoch:~/code/pkgs/ckctr/django-ai/django_ai$ python manage.py migrate examples
System check identified some issues:

WARNINGS:
bayesian_networks.BayesianNetworkNode.children: (fields.W340) null has no effect on ManyToManyField.
Operations to perform:
  Apply all migrations: examples
Running migrations:
  Applying examples.0004_bn_example...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/home/rodrigo/code/pkgs/ckctr/django-ai/django_ai/examples/migrations/0004_bn_example.py", line 57, in create_bn1_example
    mu.add_child(ui_avg1, description="mu -> userinfo.avg1")
  File "/home/rodrigo/code/django-ai/ENV/lib/python3.5/site-packages/django_dag/models.py", line 42, in add_child
    return cls.save(disable_circular_check=disable_check)
TypeError: save() got an unexpected keyword argument 'disable_circular_check'

The migrations:

# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-09-02 20:29
from __future__ import unicode_literals

from django.db import migrations

from bayesian_networks.bayespy_constants import (
	DIST_GAUSSIAN_ARD, DIST_GAMMA)
from bayesian_networks.models import BayesianNetworkNode as BNN

def create_bn1_example(apps, schema_editor):
    BayesianNetwork = apps.get_model("bayesian_networks",
                                     "BayesianNetwork")
    BayesianNetworkEdge = apps.get_model("bayesian_networks",
                                         "BayesianNetworkEdge")
    BayesianNetworkNode = apps.get_model("bayesian_networks",
                                         "BayesianNetworkNode")
    ContentType = apps.get_model("contenttypes",
                                "ContentType")
    
    bn1 = BayesianNetwork(name="BN1 (Example)")
    bn1.save()
    # import ipdb; ipdb.set_trace()
    mu = BayesianNetworkNode(
        network=bn1,
        name="mu",
        node_type=BNN.NODE_TYPE_STOCHASTIC,
        is_observable=False,
        distribution=DIST_GAUSSIAN_ARD,
        distribution_params="0, 1e-6",
        graph_interval="-10, 20"
    )
    tau = BayesianNetworkNode(
        network=bn1,
        name="tau",
        node_type=BNN.NODE_TYPE_STOCHASTIC,
        is_observable=False,
        distribution=DIST_GAMMA,
        distribution_params="1e-6, 1e-6",
        graph_interval="1e-6, 1"
    )
    ui_avg1 = BayesianNetworkNode(
        network=bn1,
        name="userinfo.avg1",
        node_type=BNN.NODE_TYPE_STOCHASTIC,
        is_observable=True,
        distribution=DIST_GAUSSIAN_ARD,
        distribution_params="mu, tau",
        ref_model=ContentType.objects.get(model="userinfo",
                                          app_label="examples"),
        ref_column="avg1",

    )
    tau.save()
    mu.save()
    ui_avg1.save()
    mu.add_child(ui_avg1, description="mu -> userinfo.avg1")
    tau.add_child(ui_avg1, description="tau -> userinfo.avg1")

However, using

    mu_to_ui_avg1 = BayesianNetworkEdge(
        network=bn1,
        description="mu -> userinfo.avg1",
        parent=mu,
        child=ui_avg1
    )
    mu_to_ui_avg1.save()

works, so for some reason the API shown in tests.py does not work in migrations.

Are the children ordered?

I would like to be able to retrieve the children in a fixed order, e.g. the order they were created.

I would also like to retrieve descendants in a fixed order.

Is there a way to guarantee this?

Populate or deactivate the wiki tab?

Would you mind either unchecking "Wiki" in your project settings or adding a landing page to help encourage a specific type of use?

Just a courtesy to users.

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.