Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:41:54+00:00 2026-05-28T06:41:54+00:00

I created routine Match, Team, etc models to create a soccer manager game and

  • 0

I created routine Match, Team, etc models to create a soccer manager game and included many known statistics as attributes (total shots, shots wide, fouls, corners,..) in the Match model. I would like to give the statistics for each halftime. Therefore I created attributes like HomeTeamFirstHalfGoals and AwayTeamSecondHalfCorners. I plan to calculate the totals like

HomeTeamTotalGoals = HomeTeamFirstHalfGoals + HomeTeamSecondHalfGoals

within Match model and display some or all those stats as a LeagueTable when requested by the user. I suppose that the user may want to see different tables like all matches played within last week or whole fixture including some of the calculable attributes like TotalGoals etc. or the whole match list of a specific team/season.

However, the code is working too slowly. I do not know whether it is due to development environment and since I have little knowledge and more confusion about mysql, I wonder how I should design the match table.

The question is, (since I heard the notion of database query, which as I see, costs the server time and cpu) should I keep the number of attributes (like AwayTeamSecondHalfCorners) minimal and calculate the dependent ones (like TotalGoals) on the fly or do the opposite to keep overhaul at the server at a minimum?

Note: I suppose everyone knows that it is so easy to create a new column by typing A3=(A1+A2) in Excel. I am confused whether it is as easy as this in ruby views or it is more efficient to do it in the mysql table? Since I have no programming background, a guide to simple sources is welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:41:55+00:00Added an answer on May 28, 2026 at 6:41 am

    Lots of ways to approach this. First thing would be to start identifying which parts of your code are fast and which are not – I’d use Ruby’s benchmark library ( http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html ).

    In general, I’d recommend storing all the discrete data, and defining methods to calculate everything that can be derived from the discrete data. So, I’d say that a team’s total goals would be something like:

    def total_goals
      first_half_goals + second_half_goals
    end
    

    With whatever logic needs to be in place to do that math. Arithmetic like this is pretty fast and shouldn’t cause any code complaints.

    One thing that would cause big slowdowns is if your database is missing any indexes – any time you have a foreign key (typically anything that ends in _id; e.g., if a Game has an away_team_id and a home_team_id, then those are probably both foreign keys), there should be a corresponding index in your database. To add an index, create a new database migration, then drop in some code like this:

    class AddIndexes < ActiveRecord::Migration
    
      def self.up
        add_index :games, :home_team_id
        add_index :games, :away_team_id
      end
    
      def self.down
        remove_index :games, :home_team_id
        remove_index :games, :away_team_id
      end
    
    end
    

    That’ll speed up any time you’re looking up the games that a team played by a very large margin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with Oracle 9.2 and JMS. I created PL/SQL routine to send
I need to create a patching routine for my application, it's really small but
i was working with a small routine that is used to create a database
I have created a Powershell routine for setting mp3 tags on songs, where I'd
In AS3, I have created a nice swear filter routine that imports a list
I have created a basic site using ASP.NET routing according to Mike Ormond's example
Here it is Create a thread in suspended state. hThrd1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.