• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:38
CET 11:38
KST 19:38
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
BGE Stara Zagora 2026 cancelled3Blizzard Classic Cup - Tastosis announced as captains12Weekly Cups (March 2-8): ByuN overcomes PvT block4GSL CK - New online series18BSL Season 224
StarCraft 2
General
BGE Stara Zagora 2026 announced ByuL: The Forgotten Master of ZvT Terran AddOns placement BGE Stara Zagora 2026 cancelled Blizzard Classic Cup - Tastosis announced as captains
Tourneys
[GSL CK] Team Maru vs. Team herO WardiTV Team League Season 10 Master Swan Open (Global Bronze-Master 2) RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 516 Specter of Death Mutation # 515 Together Forever Mutation # 514 Ulnar New Year
Brood War
General
ASL21 General Discussion BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Gypsy to Korea Are you ready for ASL 21? Hype VIDEO
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours IPSL Spring 2026 is here! ASL Season 21 Qualifiers March 7-8
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Zealot bombing is no longer popular?
Other Games
General Games
Nintendo Switch Thread PC Games Sales Thread Path of Exile No Man's Sky (PS4 and PC) Stormgate/Frost Giant Megathread
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Mexico's Drug War NASA and the Private Sector Things Aren’t Peaceful in Palestine
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
Formula 1 Discussion 2024 - 2026 Football Thread General nutrition recommendations Cricket [SPORT] TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Gaming-Related Deaths
TrAiDoS
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3096 users

The Big Programming Thread - Page 74

Forum Index > General Forum
Post a Reply
Prev 1 72 73 74 75 76 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Craton
Profile Blog Joined December 2009
United States17281 Posts
August 18 2011 01:14 GMT
#1461
If something is O(n log n) and I'm sorting 1,000,000 numbers, how do I calculate that. I'm missing something.
twitch.tv/cratonz
Frigo
Profile Joined August 2009
Hungary1023 Posts
August 18 2011 15:06 GMT
#1462
On August 18 2011 10:14 Craton wrote:
If something is O(n log n) and I'm sorting 1,000,000 numbers, how do I calculate that. I'm missing something.

The constant term in the big O expression can be arbitrary, you need specific knowledge of how many steps does the algorithm take* and what are these steps, to calculate anything. In practice it is easier and better to measure the speed of the algorithm in msec instead of steps.

*: Also these steps can vary for the input data, so you are better off calculating maximum and average cases, assuming a specific distribution of the input data or extreme cases.

On August 15 2011 08:08 EvanED wrote:
Show nested quote +
On August 14 2011 14:49 Frigo wrote:
No sorry, the compiler is quite right about warning you, it simply can't be made safe. You need to know in advance whether the line fits in your buffer, and that is simply not possible with the standard input, only with files.

This is a bit of a red herring, which can be demonstrated two ways. First, calling fgets(buf, size, stdin) works fine, and is just like calling gets(buf) except that if it reads more than size bytes, it will stop early. (There's a difference in how it handles the trailing newline if it doesn't stop early, as well.) It's not like fgets is imbued with psychic powers to see what's coming up in the stream, it just makes a "best-effort" attempt to fit it in the given buffer. The second way you can see this is calling fgets on an actual file -- it doesn't figure out that the current line is too long to fit into the buffer and does nothing, it again makes that best-effort attempt.

(And as a third way: just because the runtime thinks something is a file doesn't mean it is -- it could be a device node, a fifo, etc. -- and doesn't mean it can seek randomly.)


Obviously the statement is true only for gets, fgets is completely different, it is not "just like" gets. This difference between gets and other methods makes it possible to employ various workarounds so you don't need to know the length of the line in advance to ensure safe operation. For the same reason it is also possible to use them on streams. I'd say the guy is best off by implementing an automatically growing vector structure and associated getline functions instead of sacrificing safety with gets or fooling around with a naked fgets.
http://www.fimfiction.net/user/Treasure_Chest
catamorphist
Profile Joined May 2010
United States297 Posts
August 18 2011 18:16 GMT
#1463
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Pigsquirrel
Profile Joined August 2009
United States615 Posts
August 18 2011 18:42 GMT
#1464
Quick Java question: Is it considered bad manner to have 600+ threads in a Java application?
Craton
Profile Blog Joined December 2009
United States17281 Posts
Last Edited: 2011-08-18 19:29:40
August 18 2011 19:29 GMT
#1465
Finished interview, went okay.

On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.
twitch.tv/cratonz
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-18 19:58:56
August 18 2011 19:49 GMT
#1466
On August 19 2011 04:29 Craton wrote:
Finished interview, went okay.

Show nested quote +
On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.


Well, yeah, I'm mostly talking about people who have some amount (maybe a year or two) of C# experience. But man, there's sure a lot of low-hanging fruit:

- Cruft from prior versions. Three separate framework ways to parse XML nowadays. Non-generic collections that are basically obsolete implementations of the generic ones. A ton of different threading APIs (i.e. Thread, ThreadPool, BackgroundWorker, Task, BeginInvoke, and to some degree the new C# 5 async) that all solve overlapping problems.

- Events and properties aren't first-class, which is frustrating. I can't even get a delegate pointing to the "get" method of a property without writing a big blob of reflection. I can't pass an event down to a method so that the method can fire it without making a wrapper function.

- Type inference is spotty. Why can it infer return types of initialized local variables, but not types of initialized class properties? Why can it infer return types of anonymous functions, but not named functions? These are just arbitrary decisions.

- While I'm at it, generic type constraints are crappy and limited. I can't even write public class X<T> where T : new(int, string) and make a constructor constraint. Come on!

- Reference types are nullable by default and can't be declared as permanently non-nullable, which may be the most crash-inducing design decision ever yet invented on this planet.

- No language support for purity or immutability constraints. I figured they would add an immutability check in 4.0 when they added generic covariance and contravariance, but nope.

- No language support for declaring or enforcing the thread safety of methods or declaring a method atomic with respect to callers. No language or library support for any kind of STM.

- No language support for pattern matching or destructuring function arguments.

- No language support to make tuples easier to work with (e.g. as they have in F#.)

A lot of the problems with .NET and C# won't seem like problems until you have some experience and encounter them a few times, or unless you have used other languages that do a better job of tackling them. But if someone can't think of *any* significant problems, then I get concerned, because I worry that the person in question just doesn't know what good code is and what's a hacky workaround.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
themikeman
Profile Joined July 2011
United States8 Posts
August 19 2011 02:20 GMT
#1467
What is inheritance by reference and how do you design a class implementing inheritance by reference?
There isn't a man in history that's led a life of leisure that has been worth remembering.
Sachem
Profile Joined May 2011
United States116 Posts
August 19 2011 02:43 GMT
#1468
You should add this as a guide to obfuscation, old, but I still get a great laugh out of it: http://thc.org/root/phun/unmaintain.html
rabidch
Profile Joined January 2010
United States20289 Posts
August 19 2011 03:05 GMT
#1469
On August 19 2011 11:43 Sachem wrote:
You should add this as a guide to obfuscation, old, but I still get a great laugh out of it: http://thc.org/root/phun/unmaintain.html

i spent 5 minutes laughing at the lisp code
LiquidDota StaffOnly a true king can play the King.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
August 19 2011 22:43 GMT
#1470
A project I'm contributing to at work involves parsing a WSDL using C#. I read about XMLReader being the best option in terms of performance, so at the moment have used that. What we want to be able to do is parse the WSDL once and get all the nodes, elements and attributes then. My main question is - how to best store all this information? I was thinking dynamic arrays, and have some experience doing it with ArrayLists (using Java), but I've heard recommendations for using List<T>. Perhaps there's a better way?

I'm back home now so I do not have access to the actual code being used, but this is the pseudocode for what we're trying to do:

User selects which WSDL they want to work with

After selecting the WSDL
- parse the WSDL for the operation names (CreateCart/ModifyCart/etc)
- display the operation names in a drop-down box

After selecting the operation names..
- other stuff involving the operation they want to do, and what course to follow based on the WSDL information for that operation

There will be a lot of information to parse through to display the options to the user for how to proceed from there. Oh, and the users will be internal quality assurance testers (it's a program to help them produce tests for the constantly changing software going out to customers)

Again, I just want to know what you think would be the best way to store these different types of information after parsing the WSDL (preferably just once), and perhaps if you think there's a better way to parse the WSDL than doing XMLReader in C#.
Undefeated TL Tecmo Super Bowl League Champion
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-19 23:40:28
August 19 2011 23:37 GMT
#1471
On August 20 2011 07:43 EscPlan9 wrote:
A project I'm contributing to at work involves parsing a WSDL using C#. I read about XMLReader being the best option in terms of performance, so at the moment have used that. What we want to be able to do is parse the WSDL once and get all the nodes, elements and attributes then. My main question is - how to best store all this information? I was thinking dynamic arrays, and have some experience doing it with ArrayLists (using Java), but I've heard recommendations for using List<T>. Perhaps there's a better way?

I'm back home now so I do not have access to the actual code being used, but this is the pseudocode for what we're trying to do:

User selects which WSDL they want to work with

After selecting the WSDL
- parse the WSDL for the operation names (CreateCart/ModifyCart/etc)
- display the operation names in a drop-down box

After selecting the operation names..
- other stuff involving the operation they want to do, and what course to follow based on the WSDL information for that operation

There will be a lot of information to parse through to display the options to the user for how to proceed from there. Oh, and the users will be internal quality assurance testers (it's a program to help them produce tests for the constantly changing software going out to customers)

Again, I just want to know what you think would be the best way to store these different types of information after parsing the WSDL (preferably just once), and perhaps if you think there's a better way to parse the WSDL than doing XMLReader in C#.


XmlReader is very low-level. The typical way to parse XML in C# nowadays is using the XDocument API, which is built on top of XmlReader. I don't really see why the parser's performance would be relevant when parsing a handful of WSDL files; one wouldn't expect them to be very large.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
August 20 2011 01:53 GMT
#1472
Wow XDocument looks really handy and easy to use compared to XMLReader thanks for the suggestion!

Good point about the performance part - the largest WSDL is maybe 1 MB? Either way its not like hundreds of MBs. I don't think there would be enough of a difference for that to be such a huge factor in the decision.

This application is going to be dynamically creating labels, text fields and checkboxes based on information it receives from the WSDL (i.e. checkboxes on boolean), so I will need to organize a lot of information parsed from the WSDL for later use. Is there any significant difference between storing a lot of this information in ArrayList rather than List<t> ? I suspect this question might be too context specific for what I'm working with. If that's the case, I'm more familiar with working on ArrayLists, so I would just choose that.
Undefeated TL Tecmo Super Bowl League Champion
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-20 02:07:56
August 20 2011 02:06 GMT
#1473
On August 20 2011 10:53 EscPlan9 wrote:
Wow XDocument looks really handy and easy to use compared to XMLReader thanks for the suggestion!

Good point about the performance part - the largest WSDL is maybe 1 MB? Either way its not like hundreds of MBs. I don't think there would be enough of a difference for that to be such a huge factor in the decision.

This application is going to be dynamically creating labels, text fields and checkboxes based on information it receives from the WSDL (i.e. checkboxes on boolean), so I will need to organize a lot of information parsed from the WSDL for later use. Is there any significant difference between storing a lot of this information in ArrayList rather than List<t> ? I suspect this question might be too context specific for what I'm working with. If that's the case, I'm more familiar with working on ArrayLists, so I would just choose that.


The only significant difference is that ArrayList will be more of a pain in the ass to deal with, since it's not generic. (There's a performance problem with big ArrayLists containing value types due to boxing, but it wouldn't be significant unless you had much more data.)

I personally have literally never used an ArrayList since C# 3.0 came out, and I can't think of any reason to ever recommend it. List<T> is basically strictly better. But if you don't mind casting your data every time you access the list, then I guess you can use whatever you please.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Craton
Profile Blog Joined December 2009
United States17281 Posts
August 20 2011 02:07 GMT
#1474
Lists are basically the superior form of ArrayLists.
twitch.tv/cratonz
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 15:09 GMT
#1475
I just want to start this off with: I have no idea how to script or code. I've never done either and I've never taken classes or anything.

Having said that my question should be pretty simple.

Let me explain myself a bit, I'm working as a networking engineer for a company, we have this software called Paessler Network Monitor. We are using it to track devices on our network that are installed remotely, and to track their data usage.

This network monitoring software also comes with a separate application called the billing tool, this tool comes with a few scripts and templates scripted in lua.

Basically it has these scripts stored in a directory. You open up the billing tool, create a new customer name, and associate a template with it. Now the templates I'm guessing are customizable. And I've been playing around with it for a while, because I'm honestly not retarded, but I can't for the life of me get it to generate any kind of billing report.

If someone could explain to me specifically what I am able to modify in the script and possible values and things like that I would be eternally grateful

Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

if SensorChannel(1) ~= nil then
freeVolumeGB = 15
costPerGB = 50
currency = "$"
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024))
calculateGB = sumGB - freeVolumeGB
if calculateGB <= 0 then
calculateGB = 0
end

invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


I know it's probably very simple for one of you guys in here, but it's just not clicking for me.

Any help or advice is appreciated.
Craton
Profile Blog Joined December 2009
United States17281 Posts
Last Edited: 2011-08-22 19:21:31
August 22 2011 19:09 GMT
#1476
On August 23 2011 00:09 TadH wrote:
Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool") //load code
invoice = GetInvoice() //get invoice then stores it as 'invoice'

if SensorChannel(1) ~= nil then //dunno what sensorchannel is
freeVolumeGB = 15
costPerGB = 50
currency = "$" //probably sets as USD
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024)) //calculates total gigabytes
calculateGB = sumGB - freeVolumeGB //calculates unused gigabytes
if calculateGB <= 0 then //GB can't be negative
calculateGB = 0
end

//these lines seem to add text to the invoice being made
invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

//seems to calculate the USD cost per Kilobit
if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

//adds text to invoice
invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


Added comments. You should have documentation about what else you're able to use.
twitch.tv/cratonz
Sentient
Profile Joined April 2010
United States437 Posts
Last Edited: 2011-08-22 20:06:33
August 22 2011 20:04 GMT
#1477
On August 19 2011 04:49 catamorphist wrote:
Show nested quote +
On August 19 2011 04:29 Craton wrote:
Finished interview, went okay.

On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.


Well, yeah, I'm mostly talking about people who have some amount (maybe a year or two) of C# experience. But man, there's sure a lot of low-hanging fruit:


I've done C# exclusively for about six years, and I want to criticize some of your low-hanging fruit decisions, but first let me offer my own.

I can't stand how the DependencyProperty system in WPF and Silverlight so flagrantly violates type safety. Consider the following cases:


int a = 5;
double b = a; // totally fine
SetValue(SomeDependencyPropertyOfTypeInt, a); // success
SetValue(SomeDependencyPropertyOfTypeInt, b); // exception! b is a double, int was expected
SetValue(SomeDependencyPropertyOfTypeDouble, 5); // exception! 5 is an int. Need to pass 5.0 instead.


Worse yet, GetValue(SomeDependencyPropertyOfTypeInt) returns type object! You have to cast it to the appropriate type. More than once my head has exploded trying to refactor a DependencyProperty from one type to another, because it requires hunting down every single cast operation. I don't understand why you can't do SetValue<type>(SomeDependencyProperty, a) and GetValue<type>(SomeDependencyProperty). Then the compiler could warn you and even disambiguate the 5/5.0 issue.

About some of your examples:

- Reference types are nullable by default and can't be declared as permanently non-nullable, which may be the most crash-inducing design decision ever yet invented on this planet.

This is the one that prompted me to reply. It is not a crash-inducing design decision, but a crash-prevention design decision.

If you ever have a null reference exception, then it means your program is in a state that the programmer didn't anticipate. You can cover it up with a valid reference, but ultimately the state is still undefined. Worse, your program will probably still crash anyway, but it will happen later and in a place where it is difficult to find the original cause. Null reference exceptions pinpoint the exact place the programmer went wrong, so I make it a point to never catch them. I throw them as exceptions all the time because they are a symptom, not the cause.

If you really need a value type then use struct, not class. Or, if the object is well encapsulated, you can do something like this:

class MyClass
{
private ObjectOfSomeType myObject = new ObjectOfSomeType(); // myObject will never be null unless you set it explicitly

public MyClass()
{
// Constructor doesn't need to initialize MyObject
}
}



[The rest is spoilered so as not to clutter the thread. The ones I don't mention I either agree with (especially the type constraints with new) or am neutral on.]
+ Show Spoiler +

- Events and properties aren't first-class, which is frustrating. I can't even get a delegate pointing to the "get" method of a property without writing a big blob of reflection. I can't pass an event down to a method so that the method can fire it without making a wrapper function.

I'm not sure why you would want to do this. For events, it seems like a bad idea to release control of your events. If you really need to, you can pass an Action object via lambda with () => MyEvent(...), which saves a lot of typing. I agree it would be nice to have access to the property getters and setters, but this is only useful in the context of reflection anyway, and it doesn't take all that much to get the MethodInfo for the property's getter and setter.



- Cruft from prior versions. Three separate framework ways to parse XML nowadays. Non-generic collections that are basically obsolete implementations of the generic ones. A ton of different threading APIs (i.e. Thread, ThreadPool, BackgroundWorker, Task, BeginInvoke, and to some degree the new C# 5 async) that all solve overlapping problems.

The threading pool examples all serve very different problems that overlap only tangentially. The XML parsers make more sense in the context of mobile platforms and Silverlight where they aren't all available simultaneously.


- Type inference is spotty. Why can it infer return types of initialized local variables, but not types of initialized class properties? Why can it infer return types of anonymous functions, but not named functions? These are just arbitrary decisions.

I'm confused. It can do all of those things.

public int Blah()
{
return 5;
}

public void Blarg()
{
var a = Blah(); // works fine, a is type int
}



- No language support for purity or immutability constraints. I figured they would add an immutability check in 4.0 when they added generic covariance and contravariance, but nope.

There is the readonly keyword, which is perfectly suitable if your data is truly immutable.
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 20:04 GMT
#1478
On August 23 2011 04:09 Craton wrote:
Show nested quote +
On August 23 2011 00:09 TadH wrote:
Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool") //load code
invoice = GetInvoice() //get invoice then stores it as 'invoice'

if SensorChannel(1) ~= nil then //dunno what sensorchannel is
freeVolumeGB = 15
costPerGB = 50
currency = "$" //probably sets as USD
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024)) //calculates total gigabytes
calculateGB = sumGB - freeVolumeGB //calculates unused gigabytes
if calculateGB <= 0 then //GB can't be negative
calculateGB = 0
end

//these lines seem to add text to the invoice being made
invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

//seems to calculate the USD cost per Kilobit
if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

//adds text to invoice
invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


Added comments. You should have documentation about what else you're able to use.



I actually just found the readme file with the templates.

+ Show Spoiler +


PRTG Billing Tool Scripting Documentation
2011

To customize the billing calculations and output it is necessary to edit or write
scripts in the Lua scripting language (see Lua documentation:
http://www.lua.org/docs.html).

There are already some example scripts in the “\scripts” folder as well as example
templates in the “\templates” folder. The Billing Tool executes the script to
assign data to the template placeholders. The templates will be rendered as HTML
and PDF files afterwards.


Load Lua assembly
-----------------
To access the Billing Tool functions and data in Lua scripts, the Lua assembly
needs to be loaded:

luanet.load_assembly("Paessler.Billingtool")


Available Lua functions
-----------------------

After this step the following functions are available:

SensorChannel([channel_ID]):GetRawSum()
- Return the total bytes of the selected sensor channel for the specified
period.
- The [channel_ID] can to be found in the PRTG web interface under the
channels tab in the sensor details view.

SensorChannel([channel_ID]).Name
- Return the name of the selected sensor channel.

SensorChannel([channel_ID]).Id
- Return the ID of the selected sensor channel.

GetPercentile()
- Return the calculated percentile value for the spcified period if
available.

invoice = GetInvoice()
- Save the invoice object in the invoice variable to access invoice
functions later.

invoice:AddItem([name], [value])
- Add an item to the <#itemtable> placeholder in the template.
- With style sheets it is possible to customize the layout. Each item is
seperated into 2 columns (<td> tags).
- The columns are accessible via the CSS class "itemkey" for [name] and
"itemvalue" for [value].

invoice:SetTotal([totaltext], [totalvalue])
- Add the total value to the <#itemtable> placeholder in the template.
- The <tr> tag in the generated HTML file is accessible via the CSS ID
"total".
- Via the CSS class "totalvalue" it is possible to style the <span> tag
where the [value] will be visible.


Itemtable HTML
--------------

The following HTML is generated for the <#itemtable> placeholder:

<tr>
<td class="itemkey">
[name]
</td>
<td class="itemvalue">
[value]
</td>
</tr>
<tr id="total">
<td class="itemkey" >
[totaltext]
</td>
<td class="itemvalue">
<span class="totalvalue">[totalvalue]</span>
</td>
</tr>


So for example it says: SensorChannel([channel_ID]):GetRawSum()

Do I need to add the [ and ] or do I just add the sensor channel between the () so does it look like ([sensor channel]) or (sensor channel)

(sensor channel is the device name we're using to pull the data from, so it could be a router or a 3G card etc)

Also this: invoice:AddItem([name], [value])
- Add an item to the <#itemtable> placeholder in the template.

There is no "<#itemtable> int he template. Would I just type in <#itemtable> at the bottom of the script?

I'm just really confused, I've never had to do anything like this before. And I know it's only a basic script lol

Thanks for the help.
UltimateHurl
Profile Blog Joined September 2010
Ireland591 Posts
August 22 2011 20:19 GMT
#1479
How did I just see this thread? Did my undergrad in software engineering, about to learn lua in my spare time just because.
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 20:22 GMT
#1480
On August 23 2011 05:19 UltimateHurl wrote:
How did I just see this thread? Did my undergrad in software engineering, about to learn lua in my spare time just because.



You wanna give me a hand then? :D
Prev 1 72 73 74 75 76 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 13h 22m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Britney 38596
EffOrt 486
Mini 482
actioN 304
BeSt 292
Larva 273
Light 169
Rush 132
Leta 123
ZerO 99
[ Show more ]
ToSsGirL 54
Pusan 49
Backho 49
sorry 43
Nal_rA 36
Mind 33
Soma 21
Bale 15
ajuk12(nOOB) 9
zelot 7
Dota 2
XcaliburYe209
League of Legends
JimRising 480
Counter-Strike
olofmeister1547
shoxiejesuss646
fl0m216
zeus130
edward42
Heroes of the Storm
Khaldor152
Other Games
ceh9483
crisheroes251
Sick115
Hui .89
B2W.Neo69
NeuroSwarm56
ZerO(Twitch)7
Organizations
Dota 2
PGL Dota 2 - Main Stream11813
Other Games
gamesdonequick848
StarCraft: Brood War
lovetv 16
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• LUISG 40
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1493
• Stunt530
• TFBlade88
Upcoming Events
Replay Cast
13h 22m
CranKy Ducklings
23h 22m
RSL Revival
23h 22m
MaxPax vs Rogue
Clem vs Bunny
WardiTV Team League
1d 1h
uThermal 2v2 Circuit
1d 6h
Patches Events
1d 6h
BSL
1d 9h
Sparkling Tuna Cup
1d 23h
RSL Revival
1d 23h
ByuN vs SHIN
Maru vs Krystianer
WardiTV Team League
2 days
[ Show More ]
BSL
2 days
Replay Cast
2 days
Replay Cast
2 days
Wardi Open
3 days
Monday Night Weeklies
3 days
WardiTV Team League
4 days
GSL
4 days
The PondCast
5 days
WardiTV Team League
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-03-12
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
RSL Revival: Season 4
Nations Cup 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

CSL Elite League 2026
ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
Acropolis #4
IPSL Spring 2026
CSLAN 4
HSC XXIX
uThermal 2v2 2026 Main Event
NationLESS Cup
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.