Skip to content

Commit a9cff8e

Browse files
committed
batch rename script, attempt at The Illinois method
I did some indentation for GaussElimination I am in the middle of The Illinois method for numerical methods and I just made the file for batch renameing of files so that my media collection is noticed by Kodi. Signed-off-by: Aditya Prasad <[email protected]>
1 parent 249805a commit a9cff8e

File tree

4 files changed

+71
-32
lines changed

4 files changed

+71
-32
lines changed

GaussElimination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def storeIntoMatrix(A,n,m):
1212
print "\n Now enter the values for the " + str(n) + "x" + str(m) + " matrix"
1313
for row_number in range(n):
14-
temp_row = []
14+
temp_row = []
1515
for element_number in range(m):
1616
print "\n Enter the row - " + str(row_number+1) + " and column - " + str(element_number+1) + " element"
1717
temp_row.append(raw_input())

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ dont hesitate to contact me.
9797
Edit the START\_ROLL\_NUMBER and END\_ROLL\_NUMBER to set the range of students you want to save.
9898
For reference the roll numbers of my year students are given.
9999

100+
* **rename.py**
101+
This script was born out my requirement to mass rename files (anime, tv series, movies)
102+
so that Kodi (known as XBMC) would pick it up. I would recommend understanding the code
103+
so that you can make the appropriate changes to it and run it.It will now just show what
104+
changes the script will make.
105+
106+
* **numerical_methods**
107+
When we got [Janaki Raman Sir](https://tnjanakiraman.wordpress.com/) as our numerical methods teacher
108+
in Sem IV, he placed great emphasis on the concepts behind the methods, so I decided to implement them
109+
in python.
110+
I havent completed The Illinois method implementation, the regula falsi by itself fails in loads of cases.
111+
112+
100113

101114
### Setting up Library's
102115

numerical_methods.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,67 @@
44
# DEFINE FUNCTION IN THE CODE for now
55
# the polynomial is defined here
66
def poly(x):
7-
return (5*x*x*x+3*x+4)
8-
9-
#from math import exp
10-
#return (exp(x)+x)
11-
12-
#return (3*x*x-2*x-8)
7+
return (x*x*x)-(x)- 1
138

149
found = stop = False
1510
digits = 4
1611
pi = 3.1415926535897932384
1712

1813
# this function will give the x axis'x value at the point in the real line where the chord connecting the points (a,poly(a)) and (b,poly(b)) cross the xaxis
1914
def chord_xintercept(a,b):
20-
slope = (poly(b)-poly(a))/(b-a)
21-
22-
x_a = a + (-1*poly(a))/slope
23-
x_b = b - poly(b)/slope
24-
if(x_a == x_b):
25-
return x_a
26-
else:
27-
# debugging
28-
print "\nx_a = "+str(x_a)+" "+str(x_a==x_b)
29-
print "x_b = "+str(x_b)+"\n"
30-
return "done"
15+
return a + ( -poly(a) * (b-a) )/( poly(b) - poly(a) )
3116

3217
def regulafalsi(start,end):
18+
var = "junk"
19+
counter = 0 # to catch var staying on the same side for more than 2 iterations - Illinois algorithm
3320
while(True):
21+
temp = var
3422
# the coreof this function,
3523
var = chord_xintercept(start,end)
3624

25+
# we need to check if the same endpoint persists for more than 2 iterations ie Illinois algorithm
26+
if(counter >= 2):
27+
# we need to bias the next iteration towards start, we have had the last 2 iterations giving us the var towards end's side
28+
var = ( poly(end)*start - 0.5*poly(start)*end )/( poly(end) - 0.5*poly(start) )
29+
if(counter <= -2):
30+
# we need to bias the next iteration towards end, we have had the last 2 iterations giving us the var towards start's side
31+
var = ( 0.5*poly(start)*end - poly(end)*start )/( 0.5*poly(start) - poly(end) )
32+
33+
# if the maximum precision possible has been reached
34+
if(var == temp):
35+
return var
36+
3737
# if we are lucky enough to be looking for a root
3838
# that can be described using a finte number of digits, and find it
3939
if(poly(start) == 0):
4040
return start
4141
if(poly(end) == 0):
4242
return end
43+
4344
# if we have reached the last level of precision possible
4445
if(var == "done"):
45-
if(abs(poly(start))<abs(poly(end))):
46+
if( (start - end) <= 10**(-1*digits) ):
47+
print (start - end)
4648
return start
47-
else:
48-
return end
49-
50-
# Let us establish an alternate base condition, if the required level of precision has been reached,
51-
#if(poly(var) <= 10**(-1*digits) and poly(var) >= (-1*(10**(-1*digits)))):
52-
#return var
53-
49+
5450
# The root lies in between start and end, never play outside the boundaries :p
5551
assert (poly(start)*poly(end) <= 0)
56-
52+
5753
# check on which side our var is on towards start or end?
58-
if( (poly(var)<0 and poly(start)<0) or (poly(var)>0 and poly(start)>0) ):
59-
# its on start's side, doesnt matter wheather thats positive or negative
60-
# we know that the root is between var and end, the new start is
61-
start = var
54+
if( poly(var) * poly(end) > 0):
55+
# its on end's side, thus the new end is
56+
end = var
57+
counter = counter + 1
6258
else:
6359
# then var has to lie on the other side
64-
end = var
60+
start = var
61+
counter = counter - 1
62+
6563
# for debuggind and letting the user know whats happening
6664
#print "\nThe start,end,var is "+str(start)+" "+str(end)+" "+str(var)
6765
#print "The start,end,var is "+str(poly(start))+" "+str(poly(end))+" "+str(poly(var))
6866
print "\nThe root lies between "+str(start)+" AND "+str(end)+" \n working... shortening the range"
67+
print "\n counter is "+str(counter)
6968

7069
# the recursive function to find the root using Bisection Method-
7170
# what we do is using the range the user helped us find, we start by

rename.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This script should be kept in the same folder as the files which has to be renamed
2+
import os
3+
# This is the name of the anime/THINGY and season number
4+
name = "Bakuman S03E"
5+
total_number_of_episodes = 25
6+
# we take all the files in the directory the script has been placed
7+
for filename in os.listdir("."):
8+
# Here the code will vary depending on what the files are originally named
9+
# I download all my anime with IDM and it names the anime -> videoplayback.mp4, videoplayback_2.mp4, videoplayback_3.mp4 ... and so on
10+
# taking the first episode as a special case (strip .mp4 from filename)
11+
if(filename[:-4:] == "videoplayback"):
12+
print filename+" -->> "+ name+"0"+str(1)+".mp4"+"\n\n"
13+
#os.rename(filename, name+"0"+str(1)+".mp4") UNCOMMENT THIS
14+
# the remaining files of mine have the episode no in its title
15+
for epno in range(total_number_of_episodes,0,-1):
16+
if(not(filename[:-4:].find(str(epno))== -1)):
17+
# for episodes's 1 to 9, make it 01 - 09
18+
if(epno/10 == 0):
19+
print filename+" -->> "+ name+"0"+str(epno)+".mp4"+"\n\n"
20+
#os.rename(filename, name+"0"+str(epno)+".mp4") UNCOMMENT THIS
21+
break
22+
else:
23+
print filename+" -->> "+ name+str(epno)+".mp4"+"\n\n"
24+
#os.rename(filename, name+str(epno)+".mp4") UNCOMMENT THIS
25+
break
26+
27+
# the actual code for renaming have been commented out, remove the # and run script

0 commit comments

Comments
 (0)