Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm writing some system which uses a lot of rules. It's time for me to organize them and make them efficient. Main requirements are - business friendly, easy to understand, easy to find, easy to maintain, testable.
This question is not about how to create rule engine. I'm not writing one. My goal is to find way to maintain lot of rules in one place. and make it easy. I need some expertise advice how to do so, what approach to take. Below are examples what I did already to show that I'm working on this task and not simply ask somebody to do my job.
So far I have 3 approaches:
1) Array typed:
item=context.GetNextItem()
if ['banana','apple','orange'].Contains(item): EatRaw(item)
if ['banana','apple','potato'].Contains(item): BakeAndEat(item)
if ['meat','egg','potato','fish'].Contains(item): FryAndEat(item)
if ['pasta','egg','potato'].Contains(item): BoilAndEat(item)
2) Separated file for each item:
item=context.GetNextItem()
execfile(str(item)+'.py')
#banana.py:
EatRaw(item)
BakeAndEat(item)
#potato.py:
BakeAndEat(item)
FryAndEat(item)
BoilAndEat(item)
3) Database stored:
item=context.GetNextItem()
SQL = "SELECT rule FROM rules where item='"+str(item)+"';"
for row in cursor.execute(SQL):
eval( row.rule+"(str("+item+"))" )
Table RULES
banana,EatRaw
banana,BakeAndEat
potato,BakeAndEat
potato,FryAndEat
potato,BoilAndEat
3.a) Data in file
File RULES.txt
banana,EatRaw
banana,BakeAndEat
potato,BakeAndEat
potato,FryAndEat
potato,BoilAndEat
This file could be considered as a UI.
Each approach has it's own cons and pros but, to be honest, I'm not satisfied with any. Files grow, became bulky, hard to search, maintain and understand. Any other approach or suggestion is welcome.
Lets zoom in on this statement:
Main requirements are - business friendly, easy to understand
However, your approaches so far are easy for programmers to understand, but not particularly easy for business users to understand.
You are approaching this problem from the wrong direction, you are starting with the "which datastructure is good for ergonomics", rather than "How business will users view or modify the 'rules'"
Start with a good few rounds of UI design. Once you've got those, put it in front of potential users (if you have any), then the implementation will follow naturally, whichever closely models or supports the way the resulting UI works and is used.
edit:
a "ui" need not be a fancy single page javascript application, it can be a text file on a particular network share that gets read every day by a cron job, that's still a "user interface". Design that in a way that is compatible with both the business users needs and the available budget.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am a python beginner and I am a little experienced in OO-programming in Java and PHP and also fucntional programming in R . Thus, my question is considering the general usage of python scripts in everyday use-cases.
I want to "learn" how to think/approach a problem that I do experience when facing a situation with my software where a "script" could help me out or improve something.
For instance, I've heard friends talking about their self-made python scripts to evenly mute the audio of movies to avoid loud outliers in explosive scenes, etc. Another example, in my case righ tnow, is to filter out certain pictures with no GPS-time meta information for the timezone in order to sort these fotos in accordance with the others.
I really want to get the essence and recipe based on the aforementioned examples to better integrate Python in my everyday life and get an intuitive feeling for it. (i.e. how would a simple script look like that takes a picture, filters out its meta data, and does something -> where do I have to run the script so I can call the function with these .JPG files as its arguments?).
I would also be glad if some of you could recommend some practical tutorials or literature.
Thank you in advance :)
P.S. I know it is not a concrete question but rather it is intended to get a glimpse on a wide field of usage and thinking - but I want to get this essential take away that motivates me and shows me the direction.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am working on a project where there is a necessity to store considerable data. I was wondering what is the difference between using SQL and the datascience library in python. I intend to use SQL from its python based libraries too or use a csv file to store info if I am going to use "datascience". I am leaning very much towards "datascience" as I find the following advantages:
It is subjectively very easy to use for me. I make much less mistakes.
With my limited knowledge in runtime, I think the datascience library will be more efficient.
Most importantly, it has many inbuilt functions that could allow me to make easier functions.
However, since so many people are using SQL, I was wondering if I am missing something major, particularly in scalability.
Some people online said that SQL allows us to store files on a database, but I do not see how that makes a difference. I can simply store the file in a folder on a system and save the link in the "datascience" table.
The "datascience library" is only intended to be a tool for teaching basic concepts in an academic entry level class. Unless you are taking such a class, you should ignore it and learn more standard tools.
If it helps you, you can learn Data Science using Pandas starting just from flat data files, such as CSV and JSON. You will absolutely need to learn to interface with SQL and NoSQL servers eventually. The advantages of a database over flat files are numerous and well described elsewhere.
It's up to you whether you want to learn Pandas first and SQL second, or SQL first. Many people in the real world would have learned SQL before Python/Pandas/Data Science, so you may want to go that route.
If you go ahead and study that datascience library, you will learn some concepts, but will then have to re-learn everything in there "for real." Maybe this is best for your learning style, maybe it isn't. We don't know you well enough. Do you want academic hand holding or do you want to do things the real way?
Good luck and enjoy your journey.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Just a stupid question. I've been struggling in these last days, as a Django beginner, with the email registration (instead of the default User registration), and I've been thinking: is it better (in a process of learning) to keep on with the struggle and succeed, in the end, in the realization of the "project", or is it good too to use Django packages (like django-registration-redux)?
I mean, is it going to help me all the struggle of doing things without packages (i.e. Suppose I want to work as a Django developer), or is it useless effort?
Thank you.
Although I agree with The Laughing Man that this is opinion based, I will give my opinion hoping it will help. I have worked with Django for quite a while now, and I have learned that the answer to your question is based on a few things; Does the package have all of the functionalities you need, and a little more in case you need it? Can you and will you want to extend the functionality of the package yourself eventually? And most importantly - is the package well maintained? I found that answering yes to those three questions usually meant it was a good bet to go with the package.
In your case - it looks like the package is very well maintained - so I would go with that assuming it meets the other 2 criteria (or django-allauth, which is also excellent). No point in reinventing the wheel, especially if someone has done it better.
I agree with The Laughing Man and Hybrid for their respective view points. I have not worked with Django, but have worked with a large number of other frameworks.
I would like to add to what Hybrid has said - remember that Django is a framework and a framework usually consists of a set of packages most of which work in tandem with each other(for example a method in one package P1 may expect an argument that is actually obtained using facilities from another package P2).
Hence, if your code uses the packages available within Django then it will seamlessly work with other packages within the Django framework. If you are to (re)invent the wheel, then you may end up with some highly sophisticated and specialized functionality which would have the following characteristics:
Buggy - because you may not have handled all the use-cases and flows needed within that package.
Does not promote seamless integration with other core framework libraries. In which case you would need to write more code so that your specialized class works with the framework classes.
Re-inventing the wheel most often is a waste of time unless you are truly sure that you can solve the same problem in a real mind-blowing new way.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a MySQL database with around 10,000 articles in it, but that number will probably go up with time. I want to be able to search through these articles and pull out the most relevent results based on some keywords. I know there are a number of projects that I can plug into that can essentially do this for me. However, the application for this is very simple, and it would be nice to have direct control and working knowledge of how the whole thing operates. Therefore, I would like to look into building a very simple search engine from scratch in Python.
I'm not even sure where to start, really. I could just dump everything from the MySQL DB into a list and try to sort that list based on relevance, however that seems like it would be slow, and get slower as the amount of database items increase. I could use some basic MySQL search to get the top 100 most relevant results from what MySQL thinks, then sort those 100. But that is a two step process which may be less efficient, and I might risk missing an article if it is just out of range.
What are the best approaches I can take to this?
The best bet for you to do "Search Engine" for the 10,000 Articles is to read "Programming Collective Intelligence" by Toby Segaran. Wonderful read and to save your time go to Chapter 4 of August 2007 issue.
If you don't mind replacing the MySQL database with something else then I suggest elasticsearch, using pyes.
It has the functionality you would expect of a search engine, including full text search, great performance, pagination, more-like-this, plugin-able scoring algorithm, and is real time - so when more data is added it will be instantly shown in the search results.
If you dont want to remove the current database then you can easily run them side by side, and treat the MySQL as the master.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am new to programming. I decided to stick with Python after messing around with objective-c.
I'm beginning to get a grasp on most of the basic concepts, but as an artist, I think visually. This said, I would like to attempt to work in reverse. In other words, I'd like to start out with a complete, functional piece of software and look at the code and mess around with it to see what does what. This is kind of a similar approach to CAD modeling, where you can see which features in the model affect it, and how. This may not make sense to those who are not familiar with CAD, but I hope someone out there can relate?
Exploring existing projects is an excellent way to learn programming. Breaking existing code and fixing it is an even better way.
There are many open source projects out there that you might want to explore. Some of them are code libraries, while others are entire applications. As you are new to programming, you may want to consider looking at projects that are not too gigantic as it might be overwhelming.
Additionally, it may be even more helpful for you to dissect a program that you would actually use. I have not used this program, but PythonCAD might interest you:
http://sourceforge.net/projects/pythoncad/
This most likely does not fall into the small or simple category of open source projects but it sounds like you may already understand the intended functionality which should be of considerable aid to you in your exploration.
Browse through Google Code for open source Python projects that are of interest to you:
http://code.google.com/query/#q=python
I recommend to take a look at the PyRoom project, a no non-sense text editor for writing without distractions. It's barely 2K lines of code and seems simple to understand. You can access the repository here.